Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Wait until a condition is satisfied

NotificationsYou must be signed in to change notification settings

InterAl/wait-for-cond

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wait until a condition is satisfied. Useful for testing.

Installation

$ npm i -S wait-for-cond

Usage

The promise resolves if the condition is met at least once in the specified duration, and rejects otherwise.

varwaitFor=require('wait-for-cond');varsomeCondition=true;waitFor(function(){returnsomeCondition;},2000,'an optional reject message').then(function(){console.log('condition is fulfilled.');}).catch(function(){console.error('condition was not fulfilled in time.');});

The condition result can also be wrapped in a promise.

varwaitFor=require('wait-for-cond');varsomeCondition=true;waitFor(function(){returnnewPromise(function(resolve){returnresolve(someCondition);});},2000,'an optional reject message').then(function(){console.log('condition is fulfilled.');}).catch(function(){console.error('condition was not fulfilled in time.');});

waitFor.hold resolves if the condition remains satisfied for the entire duration, and rejects otherwise.

varwaitFor=require('wait-for-cond');varsomeCondition=true;waitFor.hold(function(){returnnewPromise(function(resolve){returnsomeCondition;});},2000,'an optional reject message').then(function(){console.log('condition remained satisfied for 2000ms');}).catch(function(){console.error('condition was unsatisfied during the 2000ms duration');});

Eventual assertions

The promise resolves if the assertion was fulfilled at least once in the specified duration, and rejects otherwise.

varassert=require('assert');varwaitFor=require('wait-for-cond');varsomeCondition=true;waitFor.assert(function(){assert(someCondition);},2000).then(function(){console.log('assertion succeeded in time.');}).catch(function(){console.log('assertion did not succeed in time.');});

Eventual holding assertions

The promise resolves if the assertion remains fulfilled for the entire specified duration, and rejects otherwise.

varassert=require('assert');varwaitFor=require('wait-for-cond');varsomeCondition=true;waitFor.assertHold(function(){assert(someCondition);},2000).then(function(){console.log('assertion was held for the entire duration.');}).catch(function(){console.log('assertion failed in the specified duration.');});

About

Wait until a condition is satisfied

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp