require('buster').spec.expose();
var expect = require('buster').expect;

var await = require('../lib/combinators/await').await;
var observe = require('../lib/combinators/observe').observe;
var Stream = require('../lib/Stream');
var resolve = require('../lib/promises').Promise.resolve;

var sentinel = { value: 'sentinel' };

function identity(x) {
	return x;
}

describe('await', function() {

	it('should await promises', function() {
		var s = await(Stream.of(resolve(sentinel)));

		return observe(function(x) {
			expect(x).toBe(sentinel);
		}, s);
	});

});

@@ -121,16 +121,71 @@
 .await;%0A
+var delay = require('../lib/combinators/timed').delay;%0A
 var obse
@@ -237,16 +237,74 @@
 bserve;%0A
+var reduce = require('../lib/combinators/reduce').reduce;%0A
 var Stre
@@ -338,22 +338,22 @@
 ');%0Avar 
-resolv
+promis
 e = requ
@@ -378,24 +378,198 @@
 es')
-.Promise.resolve
+;%0Avar resolve = promise.Promise.resolve;%0Avar delayedPromise = promise.delay;%0A%0Avar streamHelper = require('./helper/stream-helper');%0Avar createTestScheduler = streamHelper.createTestScheduler
 ;%0A%0Av
@@ -840,12 +840,470 @@
 ;%0A%09%7D);%0A%0A
+%09it('should preserve event order', function() %7B%0A%09%09var scheduler = createTestScheduler();%0A%09%09var slow = delayedPromise(10, 1, scheduler);%0A%09%09var fast = resolve(sentinel);%0A%0A%09%09// delayed promise followed by already fulfilled promise%0A%09%09var s = await(Stream.from(%5Bslow, fast%5D));%0A%0A%09%09var result = reduce(function(a, x) %7B%0A%09%09%09return a.concat(x);%0A%09%09%7D, %5B%5D, s).then(function(a) %7B%0A%09%09%09expect(a).toEqual(%5B1, sentinel%5D);%0A%09%09%7D);%0A%0A%09%09scheduler.tick(10, 1);%0A%09%09return result;%0A%09%7D);%0A%0A
 %7D);%0A

Test that await preserves event order