Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lbwa/promise-then
⤴️ Promises/A+ implementation
https://github.com/lbwa/promise-then
async asynchronous asynchronous-programming promise promises-aplus
Last synced: about 1 month ago
JSON representation
⤴️ Promises/A+ implementation
- Host: GitHub
- URL: https://github.com/lbwa/promise-then
- Owner: lbwa
- License: mit
- Created: 2020-02-14T09:10:59.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T07:17:09.000Z (about 2 years ago)
- Last Synced: 2024-12-06T00:35:26.380Z (about 2 months ago)
- Topics: async, asynchronous, asynchronous-programming, promise, promises-aplus
- Language: TypeScript
- Homepage: https://npm.im/promise-then
- Size: 1.09 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Promise/then
This library is a kind of implementation for [Promises/A+ specification][spec-promise] which is a kind of typical solution for asynchronous flow control.
The entire callbacks calling are based on [observer pattern](https://en.wikipedia.org/wiki/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_.
```text
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```
[spec-promise]: https://promisesaplus.com
## Installation
```bash
# using yarn
yarn add promise-then# using npm
npm i promise-then
```## Usage
```ts
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 */
}
)
```## Unit tests
All unit tests have been handled by [the official test suite][doc-promise-test-suite].
[doc-promise-test-suite]: https://github.com/promises-aplus/promises-tests
```bash
# using yarn
yarn test# using npm
npm t
```## Debug mode
Debug mode only works with `Visual Studio Code` breakpoint [tutorial][doc-ts-debug].
[doc-ts-debug]: https://code.visualstudio.com/docs/typescript/typescript-debugging
You can use those commands to run debug mode directly if necessary.
```bash
# using yarn
yarn run debug# using npm
npm run debug
```## Further
- [Promises/A+ specification][spec-promise]
## License
[MIT](./LICENSE) © [Bowen Liu](https://github.com/lbwa)