Last active
October 14, 2015 17:57
-
-
Save spion/42528d641779983de252 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 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
No problem with Yaku. Which version are you using?