Skip to content

Instantly share code, notes, and snippets.

@shiftkey
Created Aug 17, 2016
Embed
What would you like to do?
a quick and simple implementation of Pausable
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