Open Webifi opened 3 years ago
[EDIT] No longer applicable
EDIT: No longer applicable
Currently broken...
Should be working now
Points @cpcallen made here should all be addressed now.
Naming of new exported methods, callFunction
, queueFunction
and createThrowable
have yet to be finalized.
I think I ironed out all the bugs now.
@NeilFraser: do you want to consider this PR? The topic of implementing setTimeout
in JS Interpreter has come up in the Blockly forum again.
If you're interested in considering it I'm happy to give it a careful review as a second pair of eyes if you like.
I merged it with all the recent changes, but I'm not sure it's working correctly. Don't have time to test right now.
Allows calling anonymous interpreted functions from native code. (Includes changes in #193)
fixes #192, resolves #199, closes #147, closes #189,
Examples:
Synchronous callback from native function:
Synchronous callback from native AsyncFunction:
In both cases above, the
.then(...)
callback value handler is optional. If omitted, the value of the called interpreted function will be returned.Additional pseudo functions can be called by simply returning another Callback in the
.then()
handler viareturn interpreter.callFunction(...)
For example:
or:
Queued via queueFunction: (func is called last.)
Queued Callbacks:
Throwing exception in native AsyncFunction:
Throwing exception in native function: (Alternate to interpreter.throwException(...))
Catching exceptions in pseudo function calls from native:
Catching exceptions in pseudo function calls from native async:
Chaining thens in functions calls from native:
Implementing native timers example:
Use Callbacks in AsyncFuntion, full example:
Use Callbacks in Native Function, full example: