Skip to content

martincooper/ThreadSpark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ThreadSpark

C# Library for Functional Threading and Async Abstractions

Overview

ThreadSpark is a lightweight library which simplifies concurrency and multi-threading, handling exceptions, converting into Try and aggregating when requested.

Features :

  • Can specify max threads to run with.
  • Optional early termination of threads if one fails.
  • Aggregates errors into a Single Try if set to error on first fail.
  • Can specify Cancellation Token for early termination from external source.
  • Provides progress notification on each item complete.

Examples

Builds a collection of functions which will all be run on a seperate thread. It returns a collection of Try values, each one can be individually checked for Success / Failure.

var funcs = Enumerable
	.Range(1, 100)
	.Select(idx => fun(() => idx * 100));

// Set to run with 10 threads.
var runner = new ConcurrentFunctionRunner(10);
var result = runner.Run(funcs);

Assert.IsTrue(result.IsSucc());
Assert.AreEqual(result.GetValue().Length, 100);

Builds a collection of functions which will all be run on a seperate thread. Using "Run Until Error" will return the aggregated results if ALL successful, or the first failure which occurred.

// Using the "RunConcurrentlyUntilError" extension method to inline the call.
var result = Enumerable
	.Range(1, 100)
	.Select(idx => fun(() => idx * 100))
	.RunConcurrentlyUntilError(10);

Assert.IsTrue(result.IsSucc());
Assert.AreEqual(result.GetValue().Length, 100);

About

C# Library for Threading and Async Abstractions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages