AT module : Call back of AT.cmd (cb) doesn't remember the ATcommand : closure ? #5438
Replies: 1 comment
-
Posted at 2016-10-02 by GeekBot I think I did a mistake in my code, because now I see the cb function behaving as a closure, so sorry for the noise. Posted at 2016-10-02 by @allObjects @Geekbot, could you present a little bit more of your code? Posted at 2016-10-02 by GeekBot Sorry, I understand that you can't understand what I am talking about! Posted at 2016-10-02 by @allObjects @Geekbot, asynch has its challenges, especially in a single tasked world as JavaScript lives in. Agreed, the example has not the best introductory comment and is a bit terse... a better - more self explanatory and comprehensive - version would be something like that:
Written in a different form:
To be clear, the 1 second is true only if there is no other command going on, because the AT library can handle multiple commands which are stored in the When it is the turn of the command request - as passed with A callback function is something like a (deferred) instruction ('callback') to your friend-and-helper ('at') while telling him/her 'to go for something' (command). When she/he gets that something, your friend-and-helper will follow the given instructions... Another illustration is: you leaving a or your callback number when the called person does not take - more precisely - miss the call. When the called person will see the missed call and callback number, the person will call (you) back the call(back)number and give (you) the opportunity to say what (you) wanted to (be) said in the first place... (at least you/we hope that will happen... on multiple levels...). The timeout in this example? - What about: After that some time (timeout) of the call, you will go to the bar of your choice to get a drink without your friend's input (or company). I hope this helps somehow... if not, tell me more about the part you would like more information about... Posted at 2016-10-03 by @gfwilliams I think you're asking about the
Not sure if that makes sense? Basically if the callback function returns another function, which might be itself, then that functions will keep getting called back for each new line of data. Many AT commands return >1 line of data back, so it's a nice easy way of making sure you grab that data and only that data. Posted at 2016-10-03 by @allObjects oops... missed the detail of Posted at 2016-10-03 by GeekBot @allObjects and @gfwilliams, thank you very very much for your detailed explanations. They help me a lot in my JavaScript education. Now I understand the code and the way to use it properly. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-10-02 by GeekBot
Hello,
I am using the AT module, and the cmd function. I need to provide the AT command which leads to the call of the call back. I mean a signature like this : cb(d, ATcommand) or similar.
I am not expert in JS, but I guess that's a closure. Is it possible to make sure that the call back remembers the AT command which makes it called ?
Thanks a lot
GeekBot
Beta Was this translation helpful? Give feedback.
All reactions