Javascript Promises In Lucee
Published Saturday 4 June 2016
I got bored last night so started trying to implement Promises in Lucee based on the Promises/A+ specification. A day later and I have a working extension, so that’s nice.
The source can be found over on github ( SimonHooker/lucee-promise ). If you just want to grab the lex file, the current version is extension-lucee-promise-1.0.0.57.lex. Just download it and drop it into your contexts deploy folder and you’re good to go.
All things considered, PromiseJS API documentation and Promise on MDN both cover how to use this quite well. The only differences are as follows:
- In Lucee the promise at present does not automatically update itself with the resolved value. To retrieve the final value you must use
promise_object.value()
- Instead of
Promise.resolve( ... )
you must usePromise::resolve( ... )
- Instead of
Promise.reject( ... )
you must usePromise::reject( ... )
- Instead of
Promise.all( [ ] )
you must usePromise::all( [ ] )
- Instead of
Promise.race( [ ] )
you must usePromise::race( [ ] )
So there you have it, Promises in Lucee, hope you all have fun with them!