when-conditional
Advanced tools
Comparing version 1.0.4 to 1.1.0
{ | ||
"name": "when-conditional", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "A simple little asyncronous if check and conditional method", | ||
@@ -5,0 +5,0 @@ "main": "when.js", |
# When-conditional | ||
----------------------- | ||
A utility library for asyncronous conditional checking, and then code running. | ||
A utility library for asyncronous conditional checking, and then running a callback when the condition is true. | ||
@@ -10,7 +10,20 @@ To get started, type the following: | ||
## Syntax | ||
------------------------ | ||
```when(logicStatement, callback)``` | ||
#### Parameters | ||
###### logicStatement | ||
A function which should `return` a `truthy` statement. The return is equivalent to what you would put in an `if` statement. | ||
###### callback | ||
A function which is called when the logicStatement function returns a truthy value. | ||
## Example | ||
------------------------ | ||
The example code shown below will print out someVar is false a number of times until it becomes true, then will tell you its true and exit. | ||
```javascript | ||
var when = require('when-conditional'); | ||
@@ -57,3 +70,5 @@ var someVar = false; | ||
The when-method module is expected to be more efficient than an interval. | ||
## See you when-ever! | ||
Copyright Glen Keane - 2015 - MIT Licence |
@@ -0,4 +1,9 @@ | ||
// the require('setImmediate') adds a setImmediate polyfill to the global | ||
// scope. (this is for backwards and browser compatibility) | ||
require('setImmediate'); | ||
function when(condition, code){ | ||
if(condition()){ | ||
return code(); | ||
setImmediate(code); | ||
return; | ||
} else { | ||
@@ -8,2 +13,3 @@ setImmediate(function(){ | ||
}); | ||
return; | ||
} | ||
@@ -10,0 +16,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3432
29
73