codefrau / SqueakJS

A Squeak Smalltalk VM in Javascript
https://squeak.js.org
MIT License
365 stars 75 forks source link

adding JSObjectProxy>>await: #105

Closed zot closed 4 years ago

zot commented 4 years ago

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.

zot commented 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 :)

codefrau commented 4 years ago

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.

zot commented 4 years ago

I have no idea how to do that.

-- I'll use Pharo and see what I can find out about Monticello and packages

zot commented 4 years ago

OK, I think this was the right way to do it...

codefrau commented 4 years ago

I have not actually tested it, but it looks pretty good to me. Thank you!

zot commented 4 years ago

I meant the right way to use Monticello -- hopefully I didn't cause any weirdness