https://github.com/morulus/thens
Promise then in the plural, but something more
https://github.com/morulus/thens
Last synced: about 1 year ago
JSON representation
Promise then in the plural, but something more
- Host: GitHub
- URL: https://github.com/morulus/thens
- Owner: morulus
- License: mit
- Created: 2017-11-12T07:20:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T17:14:51.000Z (over 3 years ago)
- Last Synced: 2025-05-18T04:16:31.442Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 101 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Thens πΊπ» πΊπ» πΊπ»
==
The instrument to create async functions sequence, powered by Promise. It is Promise.`then` in the plural.
Forget about `Promise.resolve`, or `new Promise`, or `then.then.then` chain. Just compose functions and await result. Or use it as handler for native `then`, or a part of `thens`. And don't forget it **supports [generators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function%2A)**.
Enjoy.
```shell
yarn add thens
```
Usage.
```js
import thens from 'thens';
const calc = thens(
// Static
a => a + 1,
// Async like
b => Promise.resolve(b + 1),
// Real async
c => new Promise((resolve) => setTimeout(() => resolve(c + 1))),
// Like Promise.all
[
d => d + 1,
d => Promise.resolve(d + 2),
d => new Promise((resolve) => setTimeout(() => resolve(d + 3))),
],
// Generator, driven by rebound runner
function* ([e, f, g]) {
// Async inside generator
const h = yield Promise.resolve(e + f + g);
try {
throw new Error('Unexpected error');
} catch(e) {
// Error handler inside generator
return h;
}
}
);
calc(0)
.then(console.log) // 15
.catch(console.warn); // And don't forget to add final catch
```
## License
MIT, 2017, Vladimir Kalmykov