// let's say a command returns:
a
b
c
end_of_data
something_else_from_another_fn
// If you do:
at.cmd("...", 1000, function cb(d) {
});
// it gets called ONCE with 'a'
// But if you do
at.cmd("...", 1000, function cb(d) {
if (d==undefined) { timed out! }
else if (d!="end_of_data") {
// save data
return cb;
} else {
// do stuff
}
});
// You'll get a,b,c and end_of_data
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.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I think you're asking about the
return cb
bit?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.