static void QueueAsObservableExample() { PrintTitle(nameof(QueueAsObservableExample)); using (var queue = new PersistentQueueWrapper <WorkItem>("q3")) { // produce some in the background Task.Run(() => { Observable .Interval(TimeSpan.FromSeconds(0.5)) .Select(_ => new WorkItem { WorkId = DateTime.Now.ToFileTimeUtc() }) .Take(5) .Subscribe(item => queue.Enqueue(item)); Console.WriteLine("Press any key to stop producing"); }); // consume with a timeout queue .ToObservableItems( sleep_for: TimeSpan.FromSeconds(0.3), max_wait: TimeSpan.FromSeconds(1) ) .Subscribe( x => Console.WriteLine($"{x.WorkId}"), e => Console.Error.WriteLine(e), () => Console.WriteLine("No more items") ); } }
static void Example() { PrintTitle(nameof(Example)); using (var queue = new PersistentQueueWrapper <WorkItem>("q2")) { queue.Enqueue(new WorkItem { WorkId = DateTime.Now.ToFileTimeUtc() }); } using (var queue = new PersistentQueueWrapper <WorkItem>("q2")) { queue.Enqueue(NewWorkItem()); queue .ToObservableItems( sleep_for: TimeSpan.FromSeconds(0.3), max_wait: TimeSpan.FromSeconds(1) ) .Subscribe( x => Console.WriteLine($"{x.WorkId}"), e => Console.Error.WriteLine(e), () => Console.WriteLine("No more items") ); } }