https://github.com/sno2/promisify
A promisify util for Deno.
https://github.com/sno2/promisify
deno typescript
Last synced: about 2 months ago
JSON representation
A promisify util for Deno.
- Host: GitHub
- URL: https://github.com/sno2/promisify
- Owner: sno2
- License: unlicense
- Created: 2021-05-22T04:31:29.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-22T04:54:19.000Z (about 5 years ago)
- Last Synced: 2025-03-07T21:47:00.013Z (over 1 year ago)
- Topics: deno, typescript
- Language: TypeScript
- Homepage: https://deno.land/x/promisify
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# promisify
A simple Deno module for promisifying callback-based functions.
## Usage
First, import the module from the Deno Third-Party Modules Registry. After
that, you can import the `promisify` utility function.
```ts
import { promisify } from "https://deno.land/x/promisify/mod.ts";
function add(a: number, b: number, cb: (sum: number) => void) {
cb(a + b);
}
const sum = await promisify(add)(3, 5);
console.log(sum); // 8
function getItems(cb: (items: unknown[]) => void) {
throw Error("Unexpected.");
}
const items = await promisify(getItems)().catch((err) => {
console.error(err); // logs out the error because the function threw an error
});
console.log(items); // undefined
```
## License
[Unlicense](./UNLICENSE)