Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qiwi/thromise
Make sync API great again
https://github.com/qiwi/thromise
util
Last synced: 4 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 (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-26T22:21:42.000Z (about 2 months ago)
- Last Synced: 2024-11-04T01:05:35.047Z (12 days ago)
- Topics: util
- Language: JavaScript
- Homepage:
- Size: 138 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# thromise
[![CI](https://github.com/qiwi/thromise/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/qiwi/thromise/actions/workflows/ci.yaml)
[![Test Coverage](https://api.codeclimate.com/v1/badges/b83e72f80c78f6ad1d8c/test_coverage)](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)