Skip to content

Commit d2df9e5

Browse files
authored
Merge pull request #7 from dbosoft/pull/avoid_agent_blocking
avoid Agent blocking
2 parents f95674e + 8bc8bbd commit d2df9e5

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/Dbosoft.Functional/Agent.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,22 @@ await process(state, t.Item1)
125125
.ContinueWith(task =>
126126
{
127127
if (task.Status == TaskStatus.Faulted)
128-
t.Item2.SetException(task.Exception);
128+
t.Item2.SetException(task.Exception ?? new Exception("Task failed"));
129129
else
130130
{
131131
state = task.Result.Item1;
132132
t.Item2.SetResult(task.Result.Item2);
133133
}
134-
})
134+
}, TaskContinuationOptions.RunContinuationsAsynchronously)
135135
.ConfigureAwait(false);
136136
}, new ExecutionDataflowBlockOptions { CancellationToken = cancellationToken });
137137
}
138138

139139
public Task<TReply> Tell(TMsg message)
140140
{
141-
var tcs = new TaskCompletionSource<TReply>();
141+
var tcs = new TaskCompletionSource<TReply>(TaskContinuationOptions.RunContinuationsAsynchronously);
142142
_actionBlock.Post((message, tcs));
143143

144-
// this will help to relax the task scheduler, for some reason the task may block if directly returned
145-
tcs.Task.Wait(_cancellationToken);
146144
return tcs.Task;
147145
}
148146
}

0 commit comments

Comments
 (0)