NitroPromise<T> class

A composable async primitive that mirrors RN Nitro's Promise<T>.

Creating and resolving

final promise = NitroPromise<int>();
// Native code (called from C bridge):
promise.resolve(42);

// Dart consumers:
final value = await promise.future;           // standard Future<T>
promise.addOnResolvedListener((v) => print(v));

Static factories (mirror RN Nitro API)

final p1 = NitroPromise.resolved(42);         // already completed
final p2 = NitroPromise.rejected<int>(error); // already failed
final p3 = NitroPromise.async_(() async { ... return value; });

Chaining

final doubled = promise.then((v) => v * 2);          // NitroPromise<int>
final str     = promise.andThen((v) async => '$v');  // NitroPromise<String>

Constructors

NitroPromise()

Properties

future Future<T>
The underlying Dart Future. Await this for standard async/await usage.
no setter
hashCode int
The hash code for this object.
no setterinherited
isPending bool
no setter
isRejected bool
no setter
isResolved bool
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state NitroPromiseState
Current observable state of this promise.
no setter

Methods

addOnRejectedListener(void listener(Object error, StackTrace? trace)) → void
Add a callback invoked when this promise is rejected. If already rejected, invokes on the next microtask.
addOnResolvedListener(void listener(T value)) → void
Add a callback invoked when this promise resolves successfully. If already resolved, invokes immediately on the next microtask.
andThen<R>(Future<R> transform(T)) NitroPromise<R>
Asynchronously chain another async operation. Returns a NitroPromise<R>. Mirrors Promise<T>::andThen<R>(fn) in RN Nitro.
catchError(T recover(Object error)) NitroPromise<T>
Recover from a rejection by providing a fallback value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reject(Object error, [StackTrace? stackTrace]) → void
Complete this promise with an error. Mirrors Promise<T>::reject(Error). No-op if already settled (first-wins semantics, matching RN Nitro Promise).
resolve(T value) → void
Complete this promise with value. Mirrors Promise<T>::resolve(T). No-op if already settled (first-wins semantics, matching RN Nitro Promise).
then<R>(R transform(T)) NitroPromise<R>
Synchronously transform the resolved value. Returns a new NitroPromise<R>. Mirrors Promise<T>::then<R>(fn) in RN Nitro.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

all<T>(List<NitroPromise<T>> promises) NitroPromise<List<T>>
Create a promise that resolves when ALL of promises resolve. If any rejects, the returned promise rejects immediately.
async_<T>(Future<T> work()) NitroPromise<T>
Run work asynchronously and complete the returned promise with its result. Mirrors Promise<T>::async_(fn) in RN Nitro.
race<T>(List<NitroPromise<T>> promises) NitroPromise<T>
Create a promise that resolves/rejects with the first promise to settle.
rejected<T>(Object error, [StackTrace? trace]) NitroPromise<T>
A promise that is already rejected with error.
resolved<T>(T value) NitroPromise<T>
A promise that is already resolved with value.