Skip to content

Instantly share code, notes, and snippets.

@spion
Last active October 14, 2015 17:57
Show Gist options
  • Save spion/42528d641779983de252 to your computer and use it in GitHub Desktop.
Save spion/42528d641779983de252 to your computer and use it in GitHub Desktop.
var observer = require('promise-observer')
var Promise = require('bluebird');
var assert = require('assert');
function mkTransaction(tId) {
var queries = []
return {
query: function query(q) { queries.push(q); return query },
close: function() { queries.push('close ' + tId); return queries; }
}
}
function makeEnvironment() {
var emit;
var onTransaction = observer.create(function(e) { emit = e; })
return {
subscribe: onTransaction,
start: function(id) {
var tx = mkTransaction(id);
return emit(tx.query).then(tx.close)
}
}
}
function test() {
var env = makeEnvironment();
var q1 = env.subscribe(function(q) {
return Promise.resolve(1).delay(1).then(q)
});
var q2 = env.subscribe(function(q) {
return Promise.resolve(2).delay(9).then(q)
});
var q3 = env.subscribe(function(q){
return Promise.resolve(3).delay(20).then(q)
});
env.start(1).then(function(queries) {
console.log(queries);
assert.deepEqual(queries, [1,2,3,'close 1']);
})
env.start(2).then(function(queries) {
console.log(queries);
assert.deepEqual(queries, [1,2,3,'close 2']);
})
}
test();
@ysmood
Copy link

ysmood commented Oct 14, 2015

No problem with Yaku. Which version are you using?

PO [ [ 1, 2, 3, 'close 1' ],
  [ 1, 2, 3, 'close 2' ],
  [ 1, 2, 3, 'close 3' ] ]
Yaku [ [ 1, 2, 3, 'close 1' ],
  [ 1, 2, 3, 'close 2' ],
  [ 1, 2, 3, 'close 3' ] ]

@spion
Copy link
Author

spion commented Oct 14, 2015

@ysmood npm ls says

├── [email protected]
├── [email protected]
└── [email protected]

Works with the original example, but not with the updated one where the starts are delayed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment