Last active
August 29, 2015 14:16
-
-
Save GlenTiki/55b42835fd65062be312 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj = new ObjectThatDoesAsyncStuff(); //create object | |
// create some `when` checks - when these conditions are met the code in them should run | |
// (right after the variable has been changed, this async `if` should be run on it) | |
when(obj.someNumber > 10 && obj.someNumber < 20) { | |
console.log('its in range! Fire the lazer!!'); | |
} | |
when(obj.commandReady) { | |
command = obj.takeACommand(); | |
} | |
obj.doSomethingToSomeNumber(function(err){ | |
if(err) return console.log('error occured') | |
if(obj.someNumber > 10 && obj.someNumber < 20){ | |
console.log('gotta do my check here! Fire the lazer!!'); | |
} | |
}) | |
obj.addCommandToQueue('command to add', function(err){ | |
if(err) return console.log('error occured') | |
if(obj.commandReady) { | |
command = obj.takeACommand(); | |
} | |
}) | |
obj.addCommandToQueue = function(command, cb){ | |
obj.commandQueue.push(command); | |
obj.commandReady = true; | |
cb(null) | |
} | |
obj.takeACommand = function(command, cb){ | |
// you might have to do something like this because of weird | |
// observation rules on the commandReady object | |
obj.commandReady = false | |
if(obj.commandQueue.length > 0) obj.commandReady = true; | |
return obj.commandQueue.pop() | |
} | |
obj.doSomethingToSomeNumber = function(cb){ | |
obj.someNumber += 11; | |
cb(null) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment