Created
September 20, 2013 19:50
-
-
Save rektide/6642877 to your computer and use it in GitHub Desktop.
queue-sequence-spec
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 Q, Queue | |
try{ | |
Q= require("q") | |
}catch(ex){ | |
Q= require("../q") | |
} | |
try{ | |
Queue= require("q/queue") | |
}catch(ex){ | |
Queue= require("../queue") | |
} | |
global.Q= Q | |
require("./lib/jasmine-promise") | |
describe("queueing of promises", function(){ | |
it("should handle an in sequence triggering of promises", function(){ | |
var queue= Queue() | |
queue.put(Q.delay(5).then(function(){ | |
return 5 | |
})) | |
queue.put(Q.delay(30).then(function(){ | |
return 30 | |
})) | |
return expectDequeue(queue,5,30) | |
}) | |
it("should handle an out of order triggering of promises", function(){ | |
var queue= Queue() | |
queue.put(Q.delay(30).then(function(){ | |
return 30 | |
})) | |
queue.put(Q.delay(5).then(function(){ | |
return 5 | |
})) | |
return expectDequeue(queue,30,5) | |
}) | |
}) | |
function expectDequeue(queue){ | |
var expectations= Array.prototype.splice.call(arguments,0) | |
expectations.shift() | |
console.log("AT",expectations) | |
function anExpect(val){ | |
var expected= expectations.shift() | |
expect(val).toBe(expected) | |
if(expectations.length) | |
return queue.get().then(anExpect) | |
} | |
return queue.get().then(anExpect) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment