Oracle Magazine, Nov/Dec 2017
Database Developer OPEN SOURCE PROMISE CHAINING Calls to then and catch return new promise instances Of course these promises also have then and catch methods which allow calls to be chained together as needed Because these then and catch created promises are not created with the constructor function they are not resolved or rejected with a resolver function Instead if the function passed into then or catch finishes without error the promise will be resolved If the function returns a value it will set the promises value and be passed to the next then handler in the chain If an error is thrown and goes unhandled the promise will be rejected and the error will be passed to the next error handler in the chain Consider the following script const myPromise new Promise function resolve reject resolve 42 ORACLE MAGAZINE NOVEMBER OCTOBER 2017 51 myPromise then function value console log Got a value value throw new Error Error on the main thread catch function err console log Caught the error without standard try catch console log err
You must have JavaScript enabled to view digital editions.