https://github.com/qiwi/thromise
Make sync API great again
https://github.com/qiwi/thromise
util
Last synced: 5 days ago
JSON representation
Make sync API great again
- Host: GitHub
- URL: https://github.com/qiwi/thromise
- Owner: qiwi
- License: mit
- Created: 2019-07-02T09:26:01.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-04-09T16:44:28.000Z (23 days ago)
- Last Synced: 2025-04-14T09:11:24.006Z (18 days ago)
- Topics: util
- Language: JavaScript
- Homepage:
- Size: 191 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# thromise
[](https://github.com/qiwi/thromise/actions/workflows/ci.yaml)
[](https://codeclimate.com/github/qiwi/thromise/test_coverage)The Ugly.
```js
const a = fn('foo')
.then(r => b(r, 'bar')
.then(/* ... */))
```The Bad.
```js
const a = await fn('foo')
const b = await fn(a, 'bar')
```The good.
```js
const a = fn('foo')
const b = fn(a, 'bar')
```
_This is just our in-joke in the context of the Java vs JavaScript holywar_## Install
```shell
yarn add thromise
```## Usage
```js
import { loop } from 'thromise'const a = v => new Promise(resolve => setTimeout(() => resolve(v), Math.random() * 1000))
const b = v => vawait loop(t => {
const [_a, _b] = t(a, b)console.log(
'Looks synchronous:',
_a('foo'),
_b('quz'),
_a('bar'),
_a('baz'),
)
return 'result'
})// or even a bit shorter:
loop((a, b) => {
console.log(
'Looks synchronous:',
a('foo'),
b('quz'),
a('bar'),
a('baz'),
)
}, a, b)
```See also [synchronized-promise](https://github.com/Yukaii/synchronized-promise).
## License
[MIT](./LICENSE)