See https://github.com/jadonk/bonescript/issues/75
Having both synchronous and asynchronous implementations of all the
functions has become a pain to maintain. I've used node-fibers to
'my.wait_for' completion of all asynchronous events in order to provide a
synchronous return value, but this means that the synchronous calls must be
run within a fiber such that they can block (wait for the callback, but
allow the other functions to run). To facilitate this, I'm considering
bringing back the setup/run functions. The concern is this will cause some
existing applications to break. Please file feedback on this issue if you
have strong opinions and/or reply to this e-mail thread.
Example of what will break:
var b = require('bonescript');
b.pinMode('P9_14', b.ANALOG_OUTPUT);var value =
b.analogRead('P9_36');b.analogWrite('P9_14', value);
This simplest way to make this work synchronously with the new
implementation is:
var b = require('bonescript');
function setup() {
b.pinMode('P9_14', b.ANALOG_OUTPUT);
var value = b.analogRead('P9_36');
b.analogWrite('P9_14', value);
}
The most desired way to approach this problem is to rewrite your code as
asynchronous:
var b = require('bonescript');
b.pinMode('P9_14', b.ANALOG_OUTPUT, undefined, undefined, undefined, onPinMode);
function onPinMode() {
b.analogRead('P9_36', onAnalogRead);}
function onAnalogRead(x) {
b.analogWrite('P9_14', x.value);}
This has some slightly non-obvious performance advantages if you aren't
familiar with node.js's asynchronous architecture. It also has the
advantage of working over the RPC mechanism that allows you to run
BoneScript within a web page and will be the primary method I will teach
BoneScript from here on out.
To simplify writing this in the future I'll handle callbacks in other
function argument positions in functions like b.pinMode(pin, mode,
callback), rather than requiring all of the arguments. The last argument
will always be a callback.
If this just seems unmanageable to you, please let me know!
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.