A Lucee 5 extension that allows use of Javascript-style promises wthin Lucee. This extension aims to follow the Promises/A+ specification
Drop /dist/extension-lucee-promise-x.x.x.x.lex into {server|web-context}/deploy and watch the fireworks. By the time it is finished you should see a Promise.cfc in the root of your application, along with a folder /lucee-promise that contains the logic. That is all.
The syntax for lucee-promise is very similar to Javascript promises. Documentation for this can be found in the PromiseJS API documentation and Promise on MDN. The main 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.done() - 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( [ ] )
If you have any questions feel free to look me up on CFML Slack or anywhere you find me. The tests are also worth checking for some code examples, in particular /tests/core.cfc
Promise.prototype.value()( mostly used internally, but can be used in the same way asPromise.prototype.done()without any onFulfilled or onRejected callbacks )Promise.prototype.then( function( data ) {} , function( error_message ) {} )Promise.prototype.done( function( data ) {} , function( error_message ) {} )Promise.prototype.catch( function( error_message ) {} )Promise::all( array_of_promises_and_values )Promise::race( array_of_promises )Promise::resolve( value_to_return )Promise::reject( error_message )