Created
August 17, 2016 05:08
-
-
Save shiftkey/5635ca8ab73e8c39e036af6786546784 to your computer and use it in GitHub Desktop.
a quick and simple implementation of Pausable
This file contains 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
static void Main(string[] args) | |
{ | |
var range = Observable.Interval(TimeSpan.FromSeconds(1)); | |
var sampler = new Subject<bool>(); | |
var sendWhileTrue = range.CombineLatest(sampler, Tuple.Create) | |
.Where(tuple => tuple.Item2) | |
.Select(tuple => tuple.Item1) | |
.DistinctUntilChanged(); | |
var subscription = sendWhileTrue.Subscribe( | |
next => Console.WriteLine("Got value: " + next), | |
ex => Console.WriteLine("Got error: " + ex), | |
() => Console.WriteLine("Completed")); | |
string key; | |
do | |
{ | |
key = Console.ReadLine(); | |
if (key == null) break; | |
if (key.Equals("S", StringComparison.OrdinalIgnoreCase)) | |
{ | |
sampler.OnNext(true); | |
} | |
if (key.Equals("X", StringComparison.OrdinalIgnoreCase)) | |
{ | |
sampler.OnNext(false); | |
} | |
} while (!key.Equals("Q", StringComparison.OrdinalIgnoreCase)); | |
subscription.Dispose(); | |
Console.ReadKey(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment