| 1 | # async-function <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
|---|
| 2 |
|
|---|
| 3 | [![github actions][actions-image]][actions-url]
|
|---|
| 4 | [![coverage][codecov-image]][codecov-url]
|
|---|
| 5 | [![License][license-image]][license-url]
|
|---|
| 6 | [![Downloads][downloads-image]][downloads-url]
|
|---|
| 7 |
|
|---|
| 8 | [![npm badge][npm-badge-png]][package-url]
|
|---|
| 9 |
|
|---|
| 10 | A function that returns the normally hidden `AsyncFunction` constructor, when available.
|
|---|
| 11 |
|
|---|
| 12 | ## Getting started
|
|---|
| 13 |
|
|---|
| 14 | ```sh
|
|---|
| 15 | npm install --save async-function
|
|---|
| 16 | ```
|
|---|
| 17 |
|
|---|
| 18 | ## Usage/Examples
|
|---|
| 19 |
|
|---|
| 20 | ```js
|
|---|
| 21 | const assert = require('assert');
|
|---|
| 22 | const AsyncFunction = require('async-function')();
|
|---|
| 23 |
|
|---|
| 24 | const fn = new AsyncFunction('return 1');
|
|---|
| 25 |
|
|---|
| 26 | assert.equal(fn.toString(), 'async function anonymous(\n) {\nreturn 1\n}');
|
|---|
| 27 |
|
|---|
| 28 | fn().then(x => {
|
|---|
| 29 | assert.equal(x, 1);
|
|---|
| 30 | });
|
|---|
| 31 | ```
|
|---|
| 32 |
|
|---|
| 33 | ## Tests
|
|---|
| 34 |
|
|---|
| 35 | Clone the repo, `npm install`, and run `npm test`
|
|---|
| 36 |
|
|---|
| 37 | [package-url]: https://npmjs.org/package/async-function
|
|---|
| 38 | [npm-version-svg]: https://versionbadg.es/ljharb/async-function.svg
|
|---|
| 39 | [deps-svg]: https://david-dm.org/ljharb/async-function.svg
|
|---|
| 40 | [deps-url]: https://david-dm.org/ljharb/async-function
|
|---|
| 41 | [dev-deps-svg]: https://david-dm.org/ljharb/async-function/dev-status.svg
|
|---|
| 42 | [dev-deps-url]: https://david-dm.org/ljharb/async-function#info=devDependencies
|
|---|
| 43 | [npm-badge-png]: https://nodei.co/npm/async-function.png?downloads=true&stars=true
|
|---|
| 44 | [license-image]: https://img.shields.io/npm/l/async-function.svg
|
|---|
| 45 | [license-url]: LICENSE
|
|---|
| 46 | [downloads-image]: https://img.shields.io/npm/dm/async-function.svg
|
|---|
| 47 | [downloads-url]: https://npm-stat.com/charts.html?package=async-function
|
|---|
| 48 | [codecov-image]: https://codecov.io/gh/ljharb/async-function/branch/main/graphs/badge.svg
|
|---|
| 49 | [codecov-url]: https://app.codecov.io/gh/ljharb/async-function/
|
|---|
| 50 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/async-function
|
|---|
| 51 | [actions-url]: https://github.com/ljharb/async-function/actions
|
|---|