Skip to content

Instantly share code, notes, and snippets.

@matthewrobb
Created June 13, 2014 23:23
Show Gist options
  • Save matthewrobb/03fed8dabdd5cb3f47bf to your computer and use it in GitHub Desktop.
Save matthewrobb/03fed8dabdd5cb3f47bf to your computer and use it in GitHub Desktop.
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();
});
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