Last active
February 6, 2019 10:23
-
-
Save davidfowl/530c5d98c1ae216fac3df474a7914238 to your computer and use it in GitHub Desktop.
Count up from 0 to {count}, showing an item every {delay} milliseconds
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
public IObservable<int> ObservableCounter(int count, int delay) | |
{ | |
return Observable.Range(0, count).Zip( | |
Observable.Interval(TimeSpan.FromMilliseconds(delay)), (item, _) => item); | |
} |
How about...
return Observable.Range(0, count)
.Delay(TimeSpan.FromSeconds(delay));
Although wasn't in a position to test, I think this will work.
public IObservable<int> ObservableCounter(int count, int delay)
{
return Observable.For(Observable.Range(0, count), i => Observable.Return(i).Delay(TimeSpan.FromMilliseconds(delay)));
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works as well