https://github.com/sno2/async_function
A simple Deno module for accessing the `AsyncFunction` class and type.
https://github.com/sno2/async_function
async asyncfunction asynchronous deno deno-module deno-modules
Last synced: about 1 month ago
JSON representation
A simple Deno module for accessing the `AsyncFunction` class and type.
- Host: GitHub
- URL: https://github.com/sno2/async_function
- Owner: sno2
- License: mit
- Created: 2020-10-25T04:30:09.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-10-25T04:32:11.000Z (over 5 years ago)
- Last Synced: 2025-10-19T10:43:42.238Z (8 months ago)
- Topics: async, asyncfunction, asynchronous, deno, deno-module, deno-modules
- Language: TypeScript
- Homepage: https://deno.land/x/async_function
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# async_function
> A simple Deno module for accessing the `AsyncFunction` class and type.
## Why?
Despite the `Function` class being in the default global scope, the `AsyncFunction` class is not. A workaround to get this type can be achieved by just using the following code:
```ts
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
// credits: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction
```
Obviously, this is a little bit of nasty code that everyone may not want to have to include every time you need the `AsyncFunction` class. Therefore, I have created this Deno module to give you the `AsyncFunction` class just by importing it from the Deno third-party modules registry.
## Usage
Here is how you can import the `AsyncFunction` class:
```ts
import { AsyncFunction } from "http://deno.land/x/async_function/mod.ts";
```
There you go! You can now freely use the `AsyncFunction` class and all of it's glory! Of course, if we did want to add a type for `AsyncFunction` if we have an undeclared variable or just want to be explicit, we can just do `typeof AsyncFunction` to get its type. However, if you really want to have the `AsyncFunction` type imported into your code from yours truly, you can use this import statement:
```ts
import type { AsyncFunctionType } from "http://deno.land/x/async_function/mod.ts";
```
Now, we have the `AsyncFunction` class and its type for us to use. Please refer to [the MDN docs page on `AsyncFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction) for more info.
## License
By contributing your code, you agree to license your contribution under the [MIT License](./LICENSE).