An open API service indexing awesome lists of open source software.

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.

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)