# asyncf

> async/await-like helper for use in ES6 code

Latest version **1.0.2** (published 2016-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install asyncf
pnpm add asyncf
yarn add asyncf
bun add asyncf
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2016-09-07 |
| First published | 2016-09-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | math4tots |
| Maintainers | math4tots |
| Keywords | async, await, asyncf |

## Links

- npm: https://www.npmjs.com/package/asyncf
- Repository: https://github.com/math4tots/asyncf
- Homepage: https://github.com/math4tots/asyncf#readme
- Issues: https://github.com/math4tots/asyncf/issues
- npm.io page: https://npm.io/package/asyncf

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2016-09-07
- 1.0.1 — 2016-09-07
- 1.0.0 — 2016-09-07

## README

# asyncf

Tools for being able to code like you already have async/await in ES6.

Where you would use 'async function', you can use 'asyncf(function*...)'.
Where you would use 'await ...', you can use 'yield ...'.

Example

```javascript
const asyncf = require('asyncf');

const asyncMain = asyncf(function*() {

  // Using 'yield' on a Promise causes the function to
  // wait *asynchronously* until that promise is resolved.
  //
  // If the promise resolves successfully,
  // the yield expression will return the resolved value,
  //
  // If the promise rejects, an exception will throw be at the
  // yield site.


  yield asyncSleep(100);  // should return 'waking up now!'

  console.log('async main after sleeping');
});

// Any function that always returns a Promise is an
// asynchronous function. So you don't need to use the 'asyncf' function
// to create more of them.
const asyncSleep = function(timeInMillis) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve("waking up now!");
    }, timeInMillis);
  });
}


// You can just start asyncMain by calling it, or
asyncMain();

// if you wanted for asyncMain to finish, you can
// start a local 'async' context.
asyncf.start(function*() {
  yield asyncMain();
  console.error("asyncMian has finished!");
});
```

An asynchronous function is just a function that returns a Promise.

---
_Source: https://npm.io/package/asyncf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
