Re: [web-nfc] Provide option for suspending NFC watchers when "push a message" algorithm is not completed

@zolkis 
Spec may mention what happens when there are concurrent watch/push 
algorithms are running.
E.g. if nfc device comes within proximity: 1. Watchers are called, 2. 
Push message algorithm is completed.
It is implementable on linux, android, windows.

However, issue is about slightly different problem. 
Kenneth wanted to simplify life of developers by adding flag that will
 suspend watchers until push completes.

Something like adapter.pushMessage(... { target: "tag", ignoreRead: 
true })

With current API you have to do somethig like:

```javascript
var watchers = new Array();

function addWatchers() {
  navigator.nfc.requestAdapter().then((adapter) => { adapter.watch({},
 (message)=>{addItemToCart(message);} ).then((id) => 
{watchers.push(id)} ) } );
}

function removeWatchers() {
  navigator.nfc.requestAdapter().then((adapter) => { 
watchers.forEach((id) => {adapter.unwatch(id)}) } );
}

function writeTag() {
   navigator.nfc.requestAdapter().then((adapter) => { 
removeWatchers(); adapter.pushMessage(....).then(() => 
{addWatchers();})} );
}


addWatchers();
=== user clicks write tag button ===
```
Another option is to have global flag:

```javascript
var pushPending = false;
navigator.nfc.requestAdapter().then((adapter) => { adapter.watch({}, 
(message)=>{ if(pushPending) return; addItemToCart(message);} )} );
navigator.nfc.requestAdapter().then((adapter) => { pushPending = true;
 adapter.pushMessage(....).then(pushPending = false;)} );
```

-- 
GitHub Notif of comment by alexshalamov
See https://github.com/w3c/web-nfc/issues/77#issuecomment-150515672

Received on Friday, 23 October 2015 08:45:14 UTC