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

p-whilst

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-whilst - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

7

index.d.ts
/**
While `condition` returns `true`, executes `action` repeatedly, and then resolves the promise. Rejects if `action` returns a promise that rejects or if an error is thrown anywhere.
While `condition` returns `true`, executes `action` repeatedly, and then resolves the promise to the result of the last call to `action`. Rejects if `action` returns a promise that rejects or if an error is thrown anywhere.

@@ -24,3 +24,4 @@ @param condition - Expected to return a `boolean` or a `Promise<boolean>` that indicates whether to execute `action`.

condition: (value: ValueType | undefined) => PromiseLike<boolean> | boolean,
action: () => ValueType | PromiseLike<ValueType>
): Promise<void>;
action: (value: ValueType) => ValueType | PromiseLike<ValueType>,
initialValue?: ValueType,
): Promise<ValueType>;

@@ -1,9 +0,11 @@

export default async function pWhilst(condition, action) {
export default async function pWhilst(condition, action, initialValue) {
const loop = async actionResult => {
if (await condition(actionResult)) {
return loop(await action());
return loop(await action(actionResult));
}
return actionResult;
};
return loop();
return loop(initialValue);
}
{
"name": "p-whilst",
"version": "3.1.0",
"version": "3.2.0",
"description": "While a condition returns true, calls a function repeatedly, and then resolves the promise",

@@ -15,2 +15,4 @@ "license": "MIT",

"exports": "./index.js",
"types": "./index.d.ts",
"sideEffects": false,
"engines": {

@@ -17,0 +19,0 @@ "node": ">=12"

@@ -9,5 +9,5 @@ # p-whilst

```sh
npm install p-whilst
```
$ npm install p-whilst
```

@@ -32,10 +32,10 @@ ## Usage

### pWhilst(condition, action)
### pWhilst(condition, action, initialValue?)
While `condition` returns `true`, executes `action` repeatedly, and then resolves the promise. Rejects if `action` returns a promise that rejects or if an error is thrown anywhere.
While `condition` returns `true`, executes `action` repeatedly, and then resolves the promise to the result of the last call to `action`. Rejects if `action` returns a promise that rejects or if an error is thrown anywhere.
#### condition
Type: `Function`\
Arguments: The value the `action` function returns
Type: `Function`
Arguments: The value the `action` function returns or `initialValue` for the first iteration.

@@ -47,2 +47,3 @@ Expected to return a `boolean` or a `Promise<boolean>` that indicates whether to execute `action`.

Type: `Function`
Arguments: The value the last call to `action` function returns.

@@ -49,0 +50,0 @@ Action to run for each iteration.

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