annotate Implab/Promise.cs @ 209:a867536c68fc v2

Bound promise to CancellationToken Added new states to ExecutionSate enum. Added Safe.Guard() method to handle cleanup of the result of the promise
author cin
date Wed, 16 Nov 2016 03:06:08 +0300
parents 8200ab154c8a
children b1e0ffdf3451
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
1 using System;
144
8c0b95069066 DRAFT: refactoring
cin
parents: 138
diff changeset
2 using Implab.Parallels;
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
3
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
4 namespace Implab {
144
8c0b95069066 DRAFT: refactoring
cin
parents: 138
diff changeset
5 public class Promise : AbstractPromise, IDeferred {
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 144
diff changeset
6 public static readonly IPromise Success;
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
7
144
8c0b95069066 DRAFT: refactoring
cin
parents: 138
diff changeset
8 static Promise() {
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 144
diff changeset
9 Success = new SuccessPromise();
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
10 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
11
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
12 public void Resolve() {
144
8c0b95069066 DRAFT: refactoring
cin
parents: 138
diff changeset
13 SetResult();
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
14 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
15
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
16 public void Reject(Exception error) {
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
17 SetError(error);
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 144
diff changeset
18 }
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 144
diff changeset
19
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 144
diff changeset
20 public static IPromise FromException(Exception exception) {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 144
diff changeset
21 return new FailedPromise(exception);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 144
diff changeset
22 }
119
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
23 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
24 }
2573b562e328 Promises rewritten, added improved version of AsyncQueue
cin
parents: 112
diff changeset
25