Closed zot closed 4 years ago
I also added a comment to the JSBridge document after the section about promises:
"It returns a Promise. When resolved, you can access the result" JS eval: 'sqPlus(3, 4).then(function(result) { console.log(result); })'.
"Which even works from Squeak ..." (JS sqPlus: 3 and: 4) then: [:result | JS alert: result].
"But instead of using JavaScript's then() function, you can use Smalltalk's semaphores!" JS await: (JS sqPlus: 3 and: 4).
The comment can probably be improved :)
Nice! Can you also add this to the Monticello package at https://github.com/codefrau/SqueakJS/tree/master/utils/JSBridge-Core.package please? That is the canonical source, JSBidge.st is just for demo purposes.
I have no idea how to do that.
-- I'll use Pharo and see what I can find out about Monticello and packages
OK, I think this was the right way to do it...
I have not actually tested it, but it looks pretty good to me. Thank you!
I meant the right way to use Monticello -- hopefully I didn't cause any weirdness
I added JSObjectProxy>>await: which waits on a semaphore until the provided promise completes, returning the result upon success or throwing a JSException containing the JS error object upon failure.