Skip to content

twolfson/Atomic-Event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Atomic Event Emitter Donate on Gittip

Occasionally, you have a race condition between two asynchronous functions where one must run after the other. This atomic event emitter is built just for that.

var atomic = {s:{},after:function(n,f,c){c=this.s[n]=this.s[n]||[];c==1?f():c.push(f)},fire:function(n,c,f){for(c=this.s[n]||[];f=c.pop();)f();this.s[n]=1}};
setTimeout(function () {
  atomic.fire('first');
}, 100);
setTimeout(function () {
  atomic.after('first', function () {
    console.log('First must have run before this');
  });
}, 70 + (Math.random() * 60));

Tested in

This code is not tested anywhere (browsers and node).

About

Atomic event emitter for solving your race conditions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published