ceifa / wasmoon

A real lua 5.4 VM with JS bindings made with webassembly
MIT License
498 stars 32 forks source link

Implement promises support #15

Closed ceifa closed 3 years ago

ceifa commented 3 years ago

This PR is just a concept, the commented code should not be considered and will not be commented when it's done.

Related: #13

timstableford commented 3 years ago

I like the concept and awaiting all dangling promises makes sense. Doing something like this would allow Promise.all functionality. I've been thinking about how then and catch work in JS. When you call .catch or .then it actually returns a new promise eg

const o = Promise.resolve()
console.log(o === o.then(() => {}))

will print false.

I guess though it would be possible every time then or catch is called to push the new promise to the registry too

ceifa commented 3 years ago

I think I did some great things here, the API is simple and the JS-Lua bindings is pretty easy to understand, I used a lot of your code as base but removed some too. Would be nice to have your considerations @timstableford

timstableford commented 3 years ago

I think I did some great things here, the API is simple and the JS-Lua bindings is pretty easy to understand, I used a lot of your code as base but removed some too. Would be nice to have your considerations @timstableford

This is definitely a much simpler approach than mine. The lack of continuation function really helps