Struct Promise
- Namespace
- MarymoorStudios.Core.Promises
- Assembly
- MarymoorStudios.Core.Promises.dll
A representation of the future outcome of a computation.
public readonly struct Promise
- 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 successfully resolved promise.
public Promise()
Promise(Promise)
Creates a forwarded promise whose outcome will be the same as p
.
public Promise(Promise p)
Parameters
p
Promise
Promise(Resolver<Void>)
Creates an unresolved promise whose future outcome is defined by r
.
public Promise(Resolver<Void> r)
Parameters
Promise(Exception)
Creates a failed promise whose outcome is ex
.
public Promise(Exception ex)
Parameters
ex
Exception
Properties
Done
An already successfully resolved promise.
public static Promise Done { get; }
Property Value
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
Methods
AppendOne(Turn)
Dispatches a turn.
public void AppendOne(Turn turn)
Parameters
turn
TurnA turn to schedule when resolved.
From<T>(Resolver<T>)
Creates an unresolved promise whose future outcome is defined by r
.
public static Promise<T> From<T>(Resolver<T> r)
Parameters
r
Resolver<T>The resolver
Returns
- Promise<T>
Type Parameters
T
The type of the value.
From<T>(Exception)
Creates a failed promise whose outcome is ex
.
public static Promise<T> From<T>(Exception ex)
Parameters
ex
ExceptionThe failure.
Returns
- Promise<T>
Type Parameters
T
The type of the value.
From<T>(T)
An already successfully resolved promise.
public static Promise<T> From<T>(T value)
Parameters
value
TThe value
Returns
- Promise<T>
Type Parameters
T
The type of the value.
GetAwaiter()
Enables await
keyword.
public PromiseAwaiter GetAwaiter()
Returns
Operators
implicit operator Promise<Void>(Promise)
Converts a Promise to an equivalent Promise<T>.
public static implicit operator Promise<Void>(Promise p)
Parameters
p
PromiseThe promise to convert.
Returns
implicit operator Promise(Promise<Void>)
Converts a Promise<T> to an equivalent Promise.
public static implicit operator Promise(Promise<Void> p)