-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandProcessorContext.cs
More file actions
65 lines (53 loc) · 1.55 KB
/
CommandProcessorContext.cs
File metadata and controls
65 lines (53 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Threading;
using EventStore.ClientAPI;
namespace EventStore.TestClientAPI
{
public class CommandProcessorContext
{
public int ExitCode;
public Exception Error;
public string Reason;
//public readonly ILogger Log;
public readonly Client Client;
private readonly ManualResetEventSlim _doneEvent;
private int _completed;
public CommandProcessorContext(Client client, ManualResetEventSlim doneEvent)
{
Client = client;
_doneEvent = doneEvent;
}
public void Completed(int exitCode = (int)0, Exception error = null, string reason = null)
{
if (Interlocked.CompareExchange(ref _completed, 1, 0) == 0)
{
ExitCode = exitCode;
Error = error;
Reason = reason;
_doneEvent.Set();
}
}
public void Fail(Exception exc = null, string reason = null)
{
Completed((int)1, exc, reason);
}
public void Success()
{
Completed();
}
public void IsAsync()
{
_doneEvent.Reset();
}
public void WaitForCompletion()
{
if (Client.Options.Timeout < 0)
_doneEvent.Wait();
else
{
if (!_doneEvent.Wait(Client.Options.Timeout * 1000))
throw new TimeoutException("Command didn't finished within timeout.");
}
}
}
}