Created
June 13, 2014 23:23
-
-
Save matthewrobb/03fed8dabdd5cb3f47bf 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
export var counter = 0; | |
function inc_a(cb){ | |
console.log(counter++); | |
if(counter < 100) { | |
setTimeout(inc_a, 0, [ cb ]); | |
} else { | |
cb(); | |
} | |
} | |
function inc_b(){ | |
console.log(++counter); | |
if(counter < 100) { | |
setTimeout(inc_b, 0); | |
} | |
} | |
inc_a(function() { | |
counter = 0; | |
inc_b(); | |
}); |
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
System.register("tests/others/a", function(import_bind, export_bind, export_push) { | |
return { | |
deps: [ "./b" ], | |
execute: function m() { // mangle m to avoid namespace issues | |
"use strict"; | |
var counter; | |
export_bind("counter", function(){ return counter }); | |
export_push("counter", counter = 0); // returns second arg | |
function inc_a(cb){ | |
console.log(export_push("counter", counter++)); | |
if(counter < 100) { | |
setTimeout(inc_a, 0, [ cb ]); | |
} else { | |
cb(); | |
} | |
} | |
function inc_b(){ | |
console.log(export_push("counter", ++counter)); | |
if(counter < 100) { | |
setTimeout(inc_b, 0); | |
} | |
} | |
inc_a(function() { | |
export_push("counter", counter = 0); | |
inc_b(); | |
}); | |
} | |
}; | |
}); | |
// This is what the push operation would sort-of look like | |
meta.execute.push = function(name, pass_through) { | |
var newVal = my.exports[name](); // fetch the value to push from the export_binding | |
// push newVal out to subscribers of `name` | |
return pass_through; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment