# async-recursive-call

> Recursively call async function until result pass checks or cancel function returns false

Latest version **1.1.0** (published 2023-06-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-recursive-call
pnpm add async-recursive-call
yarn add async-recursive-call
bun add async-recursive-call
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-06-30 |
| First published | 2023-06-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ilias Fasikhov |
| Maintainers | ilias.fasikhov |
| Keywords | TypeScript, async, recursive, Nodejs, JavaScript |

## Links

- npm: https://www.npmjs.com/package/async-recursive-call
- Repository: https://github.com/ilyasf/async-recursive-call
- Homepage: https://github.com/ilyasf/async-recursive-call#readme
- Issues: https://github.com/ilyasf/async-recursive-call/issues
- npm.io page: https://npm.io/package/async-recursive-call

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2023-06-30
- 1.0.1 — 2023-06-28
- 1.0.0 — 2023-06-25

## README

# async-recursive-call

Small repo that provides functionality to run async code recursively
until check or cancellation functions return true.

Idea of creating was based on needs to check that API for service mesh started successfully
in a given time limit.

Can be used both on server side and browsers.

## install

`npm i async-recursive-call`

## Example of usage

```typescript
import { recursiveCall, delay } from 'async-recursive-call';

const MAX_TIME = process.env.SERVICE_MAX_START_TIME ?? 2 * 1000;

const fetchMock = () => fetch(process.env.SERVICE_URL);

....
async function checkMyServer() {
  let ready = false;
  const isSuccess = (data: any) => (data as Response).status === 200;
  let needCancel = false;

  await Promise.race([
    delay(MAX_TIME),
    recursiveCall(fetchMock, isSuccess, () => needCancel).then(
      () => (ready = true)
    )
  ]);

  needCancel = true;

  console.log("Service is ready to use ", ready);
}

checkMyServer();
```

## test

To run tests use command
`npm run test`

## license

MIT

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