This library is a kind of implementation for Promises/A+ specification which is a kind of typical solution for asynchronous flow control.
The entire callbacks calling are based on observer pattern. Not two different queues subscribe to a particular state (eg. fulfilled
OR rejected
), but just only one callbacks queue as subject's observer
to observe the state changes of promise instance.
callbacks
(not a particular type of callbacks)
+
|
observe
|
v
the state changes of Promise instance
(not a particular state)
+
|
notify
|
v
callbacks in queue
+
|
call
|
v
onFulfilled or onRejected
# using yarn
yarn add promise-then
# using npm
npm i promise-then
import Promiser from 'promise-then'
const promiser = new Promiser((resolve, reject) => {
// ... omit unrelated code
resolve(result) // or reject(reason)
})
promiser.then(
result => {
/* get `result` from promiser internal */
},
reason => {
/* handle any error in the promiser */
}
)
All unit tests have been handled by the official test suite.
# using yarn
yarn test
# using npm
npm t
Debug mode only works with Visual Studio Code
breakpoint tutorial.
You can use those commands to run debug mode directly if necessary.
# using yarn
yarn run debug
# using npm
npm run debug