Struct rquickjs_core::context::AsyncContext
source · pub struct AsyncContext(/* private fields */);
Expand description
An asynchronous single execution context with its own global variables and stack.
Can share objects with other contexts of the same runtime.
Implementations§
source§impl AsyncContext
impl AsyncContext
sourcepub unsafe fn from_raw(ctx: NonNull<JSContext>, rt: AsyncRuntime) -> Self
pub unsafe fn from_raw(ctx: NonNull<JSContext>, rt: AsyncRuntime) -> Self
Create a async context form a raw context pointer.
§Safety
The context must be of the correct runtime. The context must also have valid reference count, one which can be decremented when this object is dropped without going negative.
sourcepub async fn base(runtime: &AsyncRuntime) -> Result<Self>
pub async fn base(runtime: &AsyncRuntime) -> Result<Self>
Creates a base context with only the required functions registered.
If additional functions are required use AsyncContext::custom
,
AsyncContext::builder
or AsyncContext::full
.
sourcepub async fn custom<I: Intrinsic>(runtime: &AsyncRuntime) -> Result<Self>
pub async fn custom<I: Intrinsic>(runtime: &AsyncRuntime) -> Result<Self>
Creates a context with only the required intrinsics registered.
If additional functions are required use AsyncContext::custom
,
AsyncContext::builder
or AsyncContext::full
.
sourcepub async fn full(runtime: &AsyncRuntime) -> Result<Self>
pub async fn full(runtime: &AsyncRuntime) -> Result<Self>
Creates a context with all standard available intrinsics registered.
If precise control is required of which functions are available use
AsyncContext::custom
or AsyncContext::builder
.
sourcepub fn builder() -> ContextBuilder<()>
pub fn builder() -> ContextBuilder<()>
Create a context builder for creating a context with a specific set of intrinsics
pub async fn enable_big_num_ext(&self, enable: bool)
sourcepub fn runtime(&self) -> &AsyncRuntime
pub fn runtime(&self) -> &AsyncRuntime
Returns the associated runtime
sourcepub fn async_with<F, R>(&self, f: F) -> WithFuture<'_, F, R>where
F: for<'js> FnOnce(Ctx<'js>) -> Pin<Box<dyn Future<Output = R> + Send + 'js>> + ParallelSend,
R: ParallelSend,
pub fn async_with<F, R>(&self, f: F) -> WithFuture<'_, F, R>where
F: for<'js> FnOnce(Ctx<'js>) -> Pin<Box<dyn Future<Output = R> + Send + 'js>> + ParallelSend,
R: ParallelSend,
A entry point for manipulating and using JavaScript objects and scripts.
This function is rather limited in what environment it can capture. If you need to borrow
the environment in the closure use the async_with!
macro.
Unfortunately it is currently impossible to have closures return a generic future which has a higher rank trait bound lifetime. So, to allow closures to work, the closure must return a boxed future.
sourcepub async fn with<F, R>(&self, f: F) -> R
pub async fn with<F, R>(&self, f: F) -> R
A entry point for manipulating and using JavaScript objects and scripts.
This closure can’t return a future, if you need to await JavaScript promises prefer the
async_with!
macro.
Trait Implementations§
source§impl Clone for AsyncContext
impl Clone for AsyncContext
source§fn clone(&self) -> AsyncContext
fn clone(&self) -> AsyncContext
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for AsyncContext
impl !RefUnwindSafe for AsyncContext
impl !Send for AsyncContext
impl !Sync for AsyncContext
impl Unpin for AsyncContext
impl !UnwindSafe for AsyncContext
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more