https://github.com/ahzhezhe/async-utility
Utility to convert async function to sync function, execute async function synchronously & resolve promise synchronously.
https://github.com/ahzhezhe/async-utility
async async-await promise sync
Last synced: 8 days ago
JSON representation
Utility to convert async function to sync function, execute async function synchronously & resolve promise synchronously.
- Host: GitHub
- URL: https://github.com/ahzhezhe/async-utility
- Owner: ahzhezhe
- License: isc
- Created: 2020-02-04T02:54:07.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-24T17:35:32.000Z (about 1 year ago)
- Last Synced: 2024-05-21T03:06:59.771Z (11 months ago)
- Topics: async, async-await, promise, sync
- Language: TypeScript
- Homepage:
- Size: 1.14 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# **async-utility**
[](https://www.npmjs.com/package/async-utility)
[](https://www.npmjs.com/package/async-utility)
[](https://github.com/ahzhezhe/async-utility)
[](https://github.com/ahzhezhe/async-utility/issues)
[](https://github.com/ahzhezhe/async-utility/blob/master/LICENSE)Utility to convert async function to sync function, execute async function synchronously & resolve promise synchronously.
## **Install via NPM**
```
npm install async-utility
```## **Usage**
```typescript
import { toSync, executeSync, resolveSync } from 'async-utility';let result: number;
const asyncFn = (a: number, b: number): Promise => new Promise(resolve => resolve(a + b));// Convert async function to sync function
const syncFn = toSync(asyncFn);
result = syncFn(1, 2);// Execute async function synchronously
result = executeSync(() => asyncFn(1, 2));// Resolve promise synchronously
const promise = asyncFn(1, 2);
result = resolveSync(promise);
```