Struct Promise<T>
- Namespace
- MarymoorStudios.Core.Promises
- Assembly
- MarymoorStudios.Core.Promises.dll
A representation of the future outcome of a computation.
public readonly struct Promise<T>
Type Parameters
T
The type of the value produced by a successful outcome.
- Inherited Members
- Extension Methods
Remarks
A promise can be used to reify, track, compose, and wait for the completion of a computation.
The outcome (success or failure) cannot be known until after the computation has completed. This is called "resolving" the outcome.
Constructors
Promise()
Creates a failed promise whose outcome is UninitializedException.
public Promise()
Promise(Promise<T>)
Creates a forwarded promise whose outcome will be the same as p
.
public Promise(Promise<T> p)
Parameters
p
Promise<T>
Promise(Resolver<T>)
Creates an unresolved promise whose future outcome is defined by r
.
public Promise(Resolver<T> r)
Parameters
r
Resolver<T>
Promise(Exception)
Creates a failed promise whose outcome is ex
.
public Promise(Exception ex)
Parameters
ex
Exception
Promise(T)
Creates a successfully resolved promise.
public Promise(T value)
Parameters
value
T
Properties
Failure
The error the promise failed with.
public Exception Failure { get; }
Property Value
Remarks
REQUIRES: the promise has failed.
IsFailed
True if the promise has failed.
public bool IsFailed { get; }
Property Value
IsResolved
True if the promise is in a resolved state (either success or failure).
public bool IsResolved { get; }
Property Value
IsSuccess
True if the promise has been resolved successfully.
public bool IsSuccess { get; }
Property Value
Result
Returns the final outcome.
public T Result { get; }
Property Value
- T
Remarks
REQUIRES: the promise is resolved.
If the resolver has failed then the failing error is rethrown from this method.
Methods
GetAwaiter()
Enables await
keyword.
public PromiseAwaiter<T> GetAwaiter()