MCPcopy
hub / github.com/cujojs/when / guard

Function guard

guard.js:29–37  ·  view source on GitHub ↗

* Creates a guarded version of f that can only be entered when the supplied * condition allows. * @param {function} condition represents a critical section that may only * be entered when allowed by the condition * @param {function} f function to guard * @returns {function} guarded versio

(condition, f)

Source from the content-addressed store, hash-verified

27 * @returns {function} guarded version of f
28 */
29 function guard(condition, f) {
30 return function() {
31 var args = slice.call(arguments);
32
33 return when(condition()).withThis(this).then(function(exit) {
34 return when(f.apply(this, args))['finally'](exit);
35 });
36 };
37 }
38
39 /**
40 * Creates a condition that allows only n simultaneous executions

Callers 1

guard-test.jsFile · 0.85

Calls 2

whenFunction · 0.85
conditionFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…