Skip to content

artemiusgreat/Schedule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Schedule

Schedulers for asynchronous execution in a separate thread.

Features

  • Non-blocking execution
  • Non-competing thread-safe execution in a single or multiple threads
  • Circular buffer of tasks implementing LRU or MRU cache
  • Single-threaded timer
  • Batch execution with delay

Status

Install-Package Schedule

GitHub Workflow Status (with event) GitHub GitHub

Sample

// Guaranteed execution in a single thread for thread-safe access to context variables

var scheduler = new BackgroundRunner();
var x = scheduler.Send(() => Environment.CurrentManagedThreadId).Task.Result;
var y = Task.Run(() => scheduler.Send(() => Environment.CurrentManagedThreadId).Task.Result).Result;

Assert.Equal(x, y);

// Thread-safe single-threaded timer 

var num = new Random();
var collection = new List<int>();
var scheduler = new LoopScheduler();

Observable.Interval(span, scheduler).Subscribe(o => collection.Add(num.Next()));

Roadmap

Automatically calculate CPU load and spread work across cores.