Skip to content

Instantly share code, notes, and snippets.

@daanl
Created January 26, 2014 22:30
Show Gist options
  • Save daanl/8640316 to your computer and use it in GitHub Desktop.
Save daanl/8640316 to your computer and use it in GitHub Desktop.
RxTimer
using System;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace RxTimer
{
class Program
{
static void Main(string[] args)
{
var isBusy = false;
var interval = Observable.Interval(TimeSpan.FromSeconds(1));
interval.Where(x => !isBusy)
.Subscribe(async (item) =>
{
isBusy = true;
Console.WriteLine("Doing some background work: {0}", DateTime.UtcNow);
await Task.Delay(TimeSpan.FromSeconds(2));
Console.WriteLine("Done doing some background work: {0}", DateTime.UtcNow);
isBusy = false;
});
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment