-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove listeners and scanTag timeout #8
Comments
Glad to hear it's working well :) Not sure I fully understanding the need to remove the listeners. Are you calling Thus far I typically just listen for the tag event and respond whenever that may be (seconds/minutes/days...). |
Hi, app.post('/read', function (req, res) {
var timeout = setTimeout(function () {
res.status(504).send("No tag found");
rfid.removeListeners();
}, 10000);
rfid.scanTag().then(function(tag) {
clearTimeout(timeout);
console.log("Tag: "+ tag.uid);
var result = {};
result.uid = tag.uid.replace(/:/g,'');
rfid.readNdefData().then(function(data) {
if (data != null || data != undefined) {
var records = ndef.decodeMessage(data.toJSON().data);
if (records[0].type == "U")
result.uri = records[0].value;
else if (records[0].type == "T")
result.text = records[0].value;
}
console.log(JSON.stringify(result));
res.status(200).send(result);
});
});
}); If the result does not come within 10s, the user is informed and the promise is cancelled (he can not wait indefinitely...) Thank you, |
Awe, makes sense know seeing your use case. I could see having the ability to timeout or cancel a command. I think currently you could access the ...
var timeout = setTimeout(function () {
res.status(504).send("No tag found");
rfid.frameEmitter.removeListeners();
}, 10000);
... Since promises can't be cancelled, it might be worth looking at using Observables/RxJS which allow cancelling a "future" value |
Unfortunately that line give this error: |
Hello,
I'm playing with your library with Raspberry Pi and PN532 Breakout board. Everything is working well :)
I had the need to set a timeout to the scanTag() function if if nothing had been found. So I needed a function to stop all the pending listeners.
This worked like a charm for me:
Maybe this can be useful for others.
Anyway, maybe a timeout parameter on the scanTag() function could be the best option...
Thank you,
Alessandro
The text was updated successfully, but these errors were encountered: