Skip to content

Instantly share code, notes, and snippets.

@InfamousVague
Created August 21, 2015 00:13
Show Gist options
  • Save InfamousVague/8a5982a78c39edc96584 to your computer and use it in GitHub Desktop.
Save InfamousVague/8a5982a78c39edc96584 to your computer and use it in GitHub Desktop.
let timebomb = {
wires: function() {
Object.observe(this, (changes) => {
// It's the blue wire.
if(change.name !== 'defuse') this.charge();
});
},
clock: null,
charge: null,
defuse: function(){
clearTimeout(this.clock);
},
arm: function(time, callback) {
this.defuse = callback;
this.clock = setTimeout(callback, time);
}
};
// Usage:
setTimeout(()=>{
timebomb.arm(3000, ()=>{
console.log('boom!');
});
timebomb.defuse();
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment