Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-forever

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-forever

Run promise-returning & async functions repeatedly until you end it

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
688
decreased by-77.1%
Maintainers
1
Weekly downloads
 
Created
Source

p-forever Build Status

Run promise-returning & async functions until you end it

Think of it like an async version of while (true) {}.

Install

$ npm install p-forever

Usage

Here we create some numbered fixtures. The createFixture() function returns a Promise.

const pForever = require('p-forever');

pForever(i => {
	i++;

	if (i > 100) {
		return pForever.end;
	}

	await createFixture(i);

	return i;
}, 0);

or

const pForever = require('p-forever');

let i = 0;

pForever(() => {
	i++;

	if (i > 100) {
		return pForever.end;
	}

	await createFixture(i);
});

API

pForever(fn, [initialValue])

Returns a Promise that is fulfilled when fn returns pForever.end, or rejects if any of the promises returned from fn rejects.

fn(previousValue)

Type: Function

Receives the previously returned value. If a Promise is returned, it's awaited before calling fn again.

initialValue

Initial value to pass to fn.

pForever.end

Symbol used to end the loop.

  • p-times - Run promise-returning & async functions a specific number of times concurrently
  • p-whilst - Calls a function repeatedly while a condition returns true and then resolves the promise
  • More…

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 16 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc