Created
April 15, 2013 11:21
-
-
Save trxcllnt/5387420 to your computer and use it in GitHub Desktop.
concatMany transforms an IEnumerable to an IObservable by selecting an Observable for each Enumerable value, waiting until the Observable is complete, then moving on to the next value in the Enumerable.
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
function concatMany(enumerable:IEnumerable, selector:Function):IObservable { | |
return Observable.createWithCancelable(function(observer:IObserver):ICancelable { | |
const iterator:IEnumerator = enumerable.getEnumerator(); | |
const subscriptions:CompositeCancelable = new CompositeCancelable(); | |
var schedule:Function = function():void { | |
subscriptions.add(Scheduler.scheduleRecursive(Scheduler.defaultScheduler, function(reschedule:Function):void { | |
schedule = reschedule; | |
const item:Object = iterator.current; | |
const obs:IObservable = selector(item); | |
const completed:Function = function():void { | |
subscriptions.remove(subscription); | |
recurse(); | |
}; | |
const subscription:ICancelable = obs.subscribe(observer.onNext, completed, observer.onError); | |
subscriptions.add(subscription); | |
})); | |
}; | |
const recurse:Function = ifElse( | |
iterator.moveNext, | |
function():void { schedule(); }, | |
observer.onCompleted | |
); | |
recurse(); | |
return subscriptions; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment