Skip to content

pieroMM/wait-for-predicate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Wait For Predicate

A function which resolves a promise whether a given predicate becomes true.

Installation

npm i wait-for-predicate

Usage

const { waitForPredicate, TIMEOUT_EXPIRED } = require("wait-for-predicate");

let exit = false;
const predicate = () => !!exit;
try {
    setTimeout(() => { exit = true }, 5000);
    await waitForPredicate(predicate, { timeout: 3000 });
} catch(error) {
    if (error.message === TIMEOUT_EXPIRED) {
        console.error(TIMEOUT_EXPIRED);
    }
    throw error;
}

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published