pub struct Promise<T: 'static + FromNapiValue> { /* private fields */ }Expand description
The JavaScript Promise object representation
This Promise<T> can be awaited in the Rust
THis Promise<T> can also be passed from #[napi] fn
example:
#[napi]
pub fn await_promise_in_rust(promise: Promise<u32>) {
let value = promise.await.unwrap();
println!("{value}");
}But this Promise<T> can not be pass back to JavaScript.
If you want to use raw JavaScript Promise API, you can use the PromiseRaw instead.
Trait Implementations§
Source§impl<T: FromNapiValue> FromNapiValue for Promise<T>
impl<T: FromNapiValue> FromNapiValue for Promise<T>
Source§unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
Safety Read more
fn from_unknown(value: Unknown<'_>) -> Result<Self>
Source§impl<T: FromNapiValue> Future for Promise<T>
impl<T: FromNapiValue> Future for Promise<T>
Source§impl<T: FromNapiValue> TypeName for Promise<T>
impl<T: FromNapiValue> TypeName for Promise<T>
Source§impl<T: FromNapiValue> ValidateNapiValue for Promise<T>
impl<T: FromNapiValue> ValidateNapiValue for Promise<T>
Source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more
impl<T: FromNapiValue + Send> Send for Promise<T>
Auto Trait Implementations§
impl<T> Freeze for Promise<T>
impl<T> !RefUnwindSafe for Promise<T>
impl<T> Sync for Promise<T>where
T: Send,
impl<T> Unpin for Promise<T>
impl<T> !UnwindSafe for Promise<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more