Git Product home page Git Product logo

threadspark's Introduction

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);

threadspark's People

Contributors

martincooper avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.