|
1 | 1 | # Winton.Extensions.Threading.Actor |
2 | | -An implementation of an actor designed to integrate with C#'s async/await. |
| 2 | + |
| 3 | +A lightweight implementation of the actor pattern designed to integrate with C#'s `async`/`await` keywords. |
| 4 | +It is a richer version of the implementation outlined on [Winton's Tech Blog](https://tech.winton.com/blog/2017/03/a-tpl-actor-pattern). |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +Actors are objects that maintain a queue of work items and process that queue sequentially on a dedicated thread of |
| 9 | +execution. |
| 10 | +External agents pass work to an actor via messages. |
| 11 | +If required, messages can be used by an actor to transmit results in response to these messages. |
| 12 | +All interaction with actors is asynchronous. |
| 13 | +This is implemented here by viewing an inbound message as a delegate and an outbound response message as |
| 14 | +a `Task` or `Task<T>`. |
| 15 | + |
| 16 | +An important motivation for using actors is to avoid the sharing of data between threads within a process and |
| 17 | +so avoid the pitfalls such as deadlocks of synchronising access to that data. |
| 18 | +Rather than share data, a single entity (the actor) which carries out all actions in series is |
| 19 | +given responsibility for maintaining that data. |
| 20 | +A program can then be built as a set of interacting actors. |
| 21 | +Here execution flow is well-defined in that the scope of a single thread of execution is bounded to |
| 22 | +a single actor instance rather than it being the case that a thread of execution can wander unbounded |
| 23 | +through application code. |
| 24 | +In effect a single thread has a particular responsibility and does not stray beyond that responsibility. |
| 25 | + |
| 26 | +This library provides an implementation of an actor that allows work to be enqueued and handled sequentially. |
| 27 | +The actor can be started and stopped - though not paused - and support exists for specifying work to be done at both |
| 28 | +those state changes. |
| 29 | +In addition, a scheduler is provided to allow for the periodic scheduling of work on an actor. |
| 30 | + |
| 31 | +## Documentation |
| 32 | + |
| 33 | +The usage and API of this library are best illustrated via examples. |
| 34 | +These can be found in the [USAGE](USAGE.md) file. |
| 35 | + |
| 36 | +## Supported platforms |
| 37 | + |
| 38 | +The following platforms are supported: |
| 39 | + |
| 40 | +- .NET Core |
| 41 | +- .NET 4.5.1 |
| 42 | + |
| 43 | +## Installation |
| 44 | + |
| 45 | +The easiest way to install this library is to add a NuGet dependency on `Winton.Extensions.Threading.Actor` to your |
| 46 | +library. |
| 47 | + |
| 48 | +## Building |
| 49 | + |
| 50 | +Currently version `1.0` of the [.NET Core build tools](https://docs.microsoft.com/en-us/dotnet/articles/core/tools/) is required to build the source code. |
| 51 | +To build from Visual Studio you'll need VS 2017. |
| 52 | + |
| 53 | +Assuming you have the .NET Core build tools installed, building the library from the command-line just involves: |
| 54 | + |
| 55 | +``` |
| 56 | +dotnet restore |
| 57 | +dotnet build |
| 58 | +``` |
| 59 | + |
| 60 | +The tests use [xUnit.net](https://xunit.github.io/). |
| 61 | +To run them from the command-line use: |
| 62 | + |
| 63 | +``` |
| 64 | +dotnet test Winton.Extensions.Threading.Actor.Tests.Unit/Winton.Extensions.Threading.Actor.Tests.Unit.csproj |
| 65 | +
|
| 66 | +``` |
0 commit comments