Closed Enteee closed 8 years ago
Ok. Basic async support is implemented.
If a matcher function returns nothing (=undefined
) the matcher core will wait till the matcher function calls this.next(...)
with a boolean argument.
Example which shows the technique (but makes totally no sense ):
$.match(function(currentObject) {
var cb = this.next;
setTimeout(function() {
cb(currentObject.type == "ForkEvent");
},100);
}).then(function(){
console.log("Hey, I had to wait 100ms!");
});
Why are you using this.next instead of an optional function argument?
The number of arguments to the matcher function depends on the position in the chain. E.g. A matcher function, after 2 "followedBy's" can take up to 3 args. Making the callback an optional last function parameter, would force me to drop the "detect if the function needs the previous objects or not"-support. Making the callback the first function parameter is also bad, for functions that don't use it.
For asynchronous operations inside a rule I'd like to have a callback (instead of a return) which tells the matcher if a rule matched or not.