Skip to content

Instantly share code, notes, and snippets.

@shiftkey
Created August 17, 2016 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiftkey/5635ca8ab73e8c39e036af6786546784 to your computer and use it in GitHub Desktop.
Save shiftkey/5635ca8ab73e8c39e036af6786546784 to your computer and use it in GitHub Desktop.
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