Skip to content

Commit c237904

Browse files
author
Jos Hickson
authored
Merge pull request #2 from wintoncode/master
Sync with wintoncode
2 parents a2888f0 + 981779f commit c237904

9 files changed

Lines changed: 102 additions & 241 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Winton.Extensions.Threading.Actor
22

33
[![Build Status](https://travis-ci.org/wintoncode/Winton.Extensions.Threading.Actor.svg?branch=master)](https://travis-ci.org/wintoncode/Winton.Extensions.Threading.Actor)
4-
[![Build status](https://ci.appveyor.com/api/projects/status/p8q7dr2fnx6cxjka/branch/master?svg=true)](https://ci.appveyor.com/project/jhickson/winton-extensions-threading-actor-oadln/branch/master)
5-
4+
[![Build status](https://ci.appveyor.com/api/projects/status/nddtjsmqktd5dggu/branch/master?svg=true)](https://ci.appveyor.com/project/wintoncode/winton-extensions-threading-actor/branch/master)
65

76
A lightweight implementation of the actor pattern designed to integrate with C#'s `async`/`await` keywords.
87
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).

Winton.Extensions.Threading.Actor.Tests.Unit/Internal/ActorTaskSchedulerTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ await Launch(x =>
266266
[Fact]
267267
public void ShouldYieldCurrentThreadAndRerequestFromThreadPoolIfHaveProcessedNonLongRunningTasksContinuouslyForMoreThanAGivenTimePeriod()
268268
{
269-
var fixableUtcTimeSource = new FixableTimeSource();
270269
_scheduler = new ActorTaskScheduler(_actorId, Mock.Get(_workItemQueuer).Object, _actorTaskFactory);
271270

272271
var taskStartBarrier = new TaskCompletionSource<bool>();
@@ -281,7 +280,6 @@ public void ShouldYieldCurrentThreadAndRerequestFromThreadPoolIfHaveProcessedNon
281280
task1.Start(_scheduler);
282281
task2.Start(_scheduler);
283282
ThrowIfWaitTimesOut(taskStartBarrier.Task);
284-
fixableUtcTimeSource.Increment(TimeSpan.FromMilliseconds(250));
285283
barrier.SetResult(true);
286284

287285
task2.AwaitingShouldCompleteIn(_waitTimeout);

Winton.Extensions.Threading.Actor.Tests.Unit/Internal/ActorWorkSchedulerTests.cs

Lines changed: 86 additions & 185 deletions
Large diffs are not rendered by default.

Winton.Extensions.Threading.Actor.Tests.Utilities/FixableTimeSource.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

Winton.Extensions.Threading.Actor/Internal/StateMachine/ActiveActorState.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ protected override void StopImpl()
6464

6565
protected override void EnterImpl()
6666
{
67+
Context.StartCompletionSource.SetResult(true);
68+
6769
foreach (var task in Context.InitialWorkQueue)
6870
{
6971
Context.StartTask(task);

Winton.Extensions.Threading.Actor/Internal/StateMachine/ActorContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public ActorContext(IActorTaskFactory actorTaskFactory)
2525

2626
public List<Task> InitialWorkQueue { get; } = new List<Task>();
2727

28+
public List<Task> InitialWorkToBeCancelledQueue { get; } = new List<Task>();
29+
2830
public IActorTaskFactory ActorTaskFactory { get; }
2931

3032
public ActorStartWork StartWork

Winton.Extensions.Threading.Actor/Internal/StateMachine/InitialActorState.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ protected override void StartImpl()
1919
}
2020
else
2121
{
22-
Context.StartCompletionSource.SetResult(true);
2322
Context.SetState<ActiveActorState>();
2423
}
2524
}

Winton.Extensions.Threading.Actor/Internal/StateMachine/StartingActorState.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ protected override void EnterImpl()
3434
{
3535
await task.ConfigureAwait(false);
3636

37-
Context.StartCompletionSource.SetResult(true);
3837
Context.SetState<ActiveActorState>();
3938

4039
if (ReceivedStopSignal)
@@ -62,7 +61,14 @@ protected override void EnterImpl()
6261

6362
protected override void ScheduleImpl(Task task)
6463
{
65-
Context.InitialWorkQueue.Add(task);
64+
if (!ReceivedStopSignal)
65+
{
66+
Context.InitialWorkQueue.Add(task);
67+
}
68+
else
69+
{
70+
Context.InitialWorkToBeCancelledQueue.Add(task);
71+
}
6672
}
6773

6874
private bool ReceivedStopSignal { get; set; } = false;

Winton.Extensions.Threading.Actor/Internal/StateMachine/StoppedActorState.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Linq;
12
using System.Threading.Tasks;
23

34
namespace Winton.Extensions.Threading.Actor.Internal.StateMachine
@@ -24,12 +25,13 @@ protected override void StopImpl()
2425

2526
protected override void EnterImpl()
2627
{
27-
foreach (var task in Context.InitialWorkQueue)
28+
foreach (var task in Context.InitialWorkQueue.Concat(Context.InitialWorkToBeCancelledQueue))
2829
{
2930
task.Cancel();
3031
}
3132

3233
Context.InitialWorkQueue.Clear();
34+
Context.InitialWorkToBeCancelledQueue.Clear();
3335
}
3436
}
3537
}

0 commit comments

Comments
 (0)