Struct rquickjs::AsyncRuntime

source ·
pub struct AsyncRuntime { /* private fields */ }
Available on crate feature futures only.
Expand description

Asynchronous QuickJS runtime, entry point of the library.

Implementations§

source§

impl AsyncRuntime

source

pub fn new() -> Result<AsyncRuntime, Error>

Create a new runtime.

Will generally only fail if not enough memory was available.

§Features

If the "rust-alloc" feature is enabled the Rust’s global allocator will be used in favor of libc’s one.

source

pub fn new_with_alloc<A>(allocator: A) -> Result<AsyncRuntime, Error>
where A: Allocator + 'static,

Available on crate feature allocator only.

Create a new runtime using specified allocator

Will generally only fail if not enough memory was available.

source

pub fn weak(&self) -> AsyncWeakRuntime

Get weak ref to runtime

source

pub async fn set_interrupt_handler( &self, handler: Option<Box<dyn FnMut() -> bool + Send>> )

Set a closure which is regularly called by the engine when it is executing code. If the provided closure returns true the interpreter will raise and uncatchable exception and return control flow to the caller.

source

pub async fn set_loader<R, L>(&self, resolver: R, loader: L)
where R: Resolver + 'static, L: RawLoader + 'static,

Available on crate feature loader only.

Set the module loader

source

pub async fn set_info<S>(&self, info: S) -> Result<(), Error>
where S: Into<Vec<u8>>,

Set the info of the runtime

source

pub async fn set_memory_limit(&self, limit: usize)

Set a limit on the max amount of memory the runtime will use.

Setting the limit to 0 is equivalent to unlimited memory.

Note that is a Noop when a custom allocator is being used, as is the case for the “rust-alloc” or “allocator” features.

source

pub async fn set_max_stack_size(&self, limit: usize)

Set a limit on the max size of stack the runtime will use.

The default values is 256x1024 bytes.

source

pub async fn set_gc_threshold(&self, threshold: usize)

Set a memory threshold for garbage collection.

source

pub async fn run_gc(&self)

Manually run the garbage collection.

Most QuickJS values are reference counted and will automatically free themselves when they have no more references. The garbage collector is only for collecting cyclic references.

source

pub async fn memory_usage(&self) -> JSMemoryUsage

Get memory usage stats

source

pub async fn is_job_pending(&self) -> bool

Test for pending jobs

Returns true when at least one job is pending.

source

pub async fn execute_pending_job(&self) -> Result<bool, AsyncJobException>

Execute first pending job

Returns true when job was executed or false when queue is empty or error when exception thrown under execution.

source

pub async fn idle(&self)

Run all futures and jobs in the runtime until all are finished.

source

pub fn drive(&self) -> DriveFuture

Returns a future that completes when the runtime is dropped. If the future is polled it will drive futures spawned inside the runtime completing them even if runtime is currently not in use.

Trait Implementations§

source§

impl Clone for AsyncRuntime

source§

fn clone(&self) -> AsyncRuntime

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Send for AsyncRuntime

source§

impl Sync for AsyncRuntime

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ParallelSend for T
where T: Send,