Marathon 1.0.0

.NET Standard 2.1
dotnet add package Marathon --version 1.0.0
NuGet\Install-Package Marathon -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Marathon" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Marathon --version 1.0.0
#r "nuget: Marathon, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Marathon as a Cake Addin
#addin nuget:?package=Marathon&version=1.0.0

// Install Marathon as a Cake Tool
#tool nuget:?package=Marathon&version=1.0.0

Marathon

The Marathon library provides a .NET, cross-platform, lightweight task running library. It facilitates the composition of tasks for sequential and parallel execution, or both. Further, it provides synchronous and asynchronous implementations of the composed tasks in a transparent manner to the user.

Leveraging the Task Parallel Library is even easier, clearer, and more expressive when using Marathon.

Compatibility

  • .NET Standard 2.1

Installation

  • NuGet: coming soon!

Hello World

// Create some Actions to execute.
Action hello = delegate { Console.Write("Hello, "); }
Action world = delegate { Console.Write("world"); }
Action emphasis = delegate { Console.Write("!"); }
Action nl = delegate { Console.WriteLine(); }
// The 'Runner' class builds and runs tasks from the given Actions.
Runner runner = new Runner();  
runner.Run(hello)     // `Run()` starts building and running the given delegates.
      .Then(world)    // `Then()` waits for the previous Task to finish before starting.
      .Then(emphasis)
      .And(emphasis)  // `And()` starts running the given delegate at the same time as the previous one.
      .And(emphasis)
      .Then(nl)
      .Sync();        // `Sync()` waits for all the tasks to finish, blocking the current thread.

Output:

> Hello, world!!!
>

In-Depth

Marathon tasks are built starting with the Runner class. As the only class that implements the IRun interface, it exposes the Run() method which starts the scheduling of Actions as tasks to be run. The Run() method returns a BaseRunner which exposes the two run types in Marathon, And and Then.

Ands are the implementation of the IAnd interface and tell the scheduler that the given Action should be run in parallel as the previous Action. These can be chained as many times as desired. For example, BaseRunner tasks = runner.Run(action1).And(action2).And(action3) would build tasks to run action1, action2, and action3 at the same time once either the Sync() or Async() method is invoked.

Thens are the implementation of the IThen interface and tell the scheduler that the given Action should only be run after the previous Action has finished. These can be chained as many times as desired. For example, BaseRunner tasks = runner.Run(action1).Then(action2).Then(action3) would build tasks to run action1, then action2, and finally action3 once either the Sync() or Async() method is invoked.

Lastly, the crème de la crème that makes Marathon special: the ability to transparently execute the scheduled tasks synchronously or asynchronously. This is possible because the BaseRunner class implements the ISync and IAsync interfaces. These two interfaces expose the Sync() and Async() methods, respectively, and end the chain of a Runner's tasks. The Sync() method schedules the tasks to be executed synchronously, blocking the current thread. Alternatively, the Async() method schedules the tasks to be executed asynchronously, just how you'd expect normal async methods in .NET to work.

Examples

See here in the wiki.

Changes

  • Added examples to wiki.
  • Updated README file.
  • Tentatively finished initial pre-release.
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 385 12/14/2019

1.0.0 - Initial release.