##// END OF EJS Templates
container configuration docs
container configuration docs

File last commit:

r249:d82909310094 v3
r276:b4e0f81c7425 v3
Show More
PromiseActionReaction`1.cs
90 lines | 3.1 KiB | text/x-csharp | CSharpLexer
/ Implab / PromiseActionReaction`1.cs
cin
working on promises
r247 using System;
using System.Diagnostics;
namespace Implab {
cin
Implab.Test moved to xunit...
r249 class PromiseActionReaction<T> : IResolvable<T> {
cin
working on promises
r247 readonly Deferred m_next;
cin
Implab.Test moved to xunit...
r249 readonly IDispatcher m_dispatcher;
readonly Action<T, Deferred> m_fulfilled;
readonly Action<Exception, Deferred> m_rejected;
cin
Added awaiters to promises...
r248 public IPromise Promise {
get { return m_next.Promise; }
}
cin
Implab.Test moved to xunit...
r249 public PromiseActionReaction(Action<T, Deferred> fulfilled, Action<Exception, Deferred> rejected, Deferred next, IDispatcher dispatcher) {
m_next = next;
m_fulfilled = fulfilled;
m_rejected = rejected;
m_dispatcher = dispatcher;
cin
working on promises
r247 }
cin
Implab.Test moved to xunit...
r249 public void Resolve(T result) {
if (m_fulfilled != null) {
if (m_dispatcher != null)
m_dispatcher.Enqueue(ResolveImpl, result);
else
ResolveImpl(result);
} else {
m_next.Resolve();
}
}
cin
working on promises
r247
cin
Implab.Test moved to xunit...
r249 void ResolveImpl (T result) {
m_fulfilled(result, m_next);
}
public void Reject(Exception error) {
if (m_fulfilled != null) {
if (m_dispatcher != null)
m_dispatcher.Enqueue(RejectImpl, error);
else
RejectImpl(error);
} else {
m_next.Reject(error);
}
cin
working on promises
r247 }
cin
Implab.Test moved to xunit...
r249 void RejectImpl(Exception error) {
m_rejected(error, m_next);
}
cin
working on promises
r247
cin
Implab.Test moved to xunit...
r249 public static PromiseActionReaction<T> Create(Action<T> fulfilled, Action<Exception> rejected, IDispatcher dispatcher) {
return new PromiseActionReaction<T>(
fulfilled != null ? PromiseHandler.Create(fulfilled) : null,
rejected != null ? PromiseHandler.Create(rejected) : null,
new Deferred(),
dispatcher
);
cin
working on promises
r247 }
cin
Implab.Test moved to xunit...
r249 public static PromiseActionReaction<T> Create(Func<T,IPromise> fulfilled, Action<Exception> rejected, IDispatcher dispatcher) {
return new PromiseActionReaction<T>(
fulfilled != null ? PromiseHandler.Create(fulfilled) : null,
rejected != null ? PromiseHandler.Create(rejected) : null,
new Deferred(),
dispatcher
);
cin
Added awaiters to promises...
r248 }
cin
working on promises
r247
cin
Implab.Test moved to xunit...
r249 public static PromiseActionReaction<T> Create(Action<T> fulfilled, Func<Exception, IPromise> rejected, IDispatcher dispatcher) {
return new PromiseActionReaction<T>(
fulfilled != null ? PromiseHandler.Create(fulfilled) : null,
rejected != null ? PromiseHandler.Create(rejected) : null,
new Deferred(),
dispatcher
);
cin
working on promises
r247 }
cin
Implab.Test moved to xunit...
r249 public static PromiseActionReaction<T> Create(Func<T,IPromise> fulfilled, Func<Exception, IPromise> rejected, IDispatcher dispatcher) {
return new PromiseActionReaction<T>(
fulfilled != null ? PromiseHandler.Create(fulfilled) : null,
rejected != null ? PromiseHandler.Create(rejected) : null,
new Deferred(),
dispatcher
);
cin
working on promises
r247 }
}
}