Struct jlrs::extensions::multitask::runtime::AsyncJulia [−][src]
pub struct AsyncJulia { /* fields omitted */ }
Expand description
A handle to the async runtime. It can be used to include files and send new tasks. The runtime shuts down when the last handle is dropped.
All initialization methods share three arguments:
max_n_tasks
: the maximum number of tasks that can run at the same time.channel_capacity
: the capacity of the channel used to communicate with the runtime. If it’s 0 an unbounded channel is used.recv_timeout
: timeout used when receiving messages on the communication channel. If no new message is received before the timeout and tasks are running, events are processed.
Implementations
pub unsafe fn init(
max_n_tasks: usize,
channel_capacity: usize,
recv_timeout: Duration
) -> JlrsResult<(Self, ThreadHandle<JlrsResult<()>>)>
pub unsafe fn init(
max_n_tasks: usize,
channel_capacity: usize,
recv_timeout: Duration
) -> JlrsResult<(Self, ThreadHandle<JlrsResult<()>>)>
Initialize Julia in a new thread.
This function returns an error if the JULIA_NUM_THREADS
environment variable is set
to a value smaller than 3 or some invalid value, or if Julia has already been initialized.
If the environment variable is not set it’s set to auto
. See the struct-level
documentation for more info about this method’s arguments.
Safety: this method can race with other crates that try to initialize Julia at the same time.
pub async unsafe fn init_async(
max_n_tasks: usize,
channel_capacity: usize,
recv_timeout: Duration
) -> JlrsResult<(Self, JoinHandle<JlrsResult<()>>)>
pub async unsafe fn init_async(
max_n_tasks: usize,
channel_capacity: usize,
recv_timeout: Duration
) -> JlrsResult<(Self, JoinHandle<JlrsResult<()>>)>
Initialize Julia as a blocking task.
This function returns an error if the JULIA_NUM_THREADS
environment variable is set
to a value smaller than 3 or some invalid value, or if Julia has already been initialized.
If the environment variable is not set it’s set to auto
. See the struct-level
documentation for more info about this method’s arguments.
Safety: this method can race with other crates that try to initialize Julia at the same time.
pub unsafe fn init_with_image<P, Q>(
max_n_tasks: usize,
channel_capacity: usize,
recv_timeout: Duration,
julia_bindir: P,
image_path: Q
) -> JlrsResult<(Self, ThreadHandle<JlrsResult<()>>)> where
P: AsRef<Path> + Send + 'static,
Q: AsRef<Path> + Send + 'static,
pub unsafe fn init_with_image<P, Q>(
max_n_tasks: usize,
channel_capacity: usize,
recv_timeout: Duration,
julia_bindir: P,
image_path: Q
) -> JlrsResult<(Self, ThreadHandle<JlrsResult<()>>)> where
P: AsRef<Path> + Send + 'static,
Q: AsRef<Path> + Send + 'static,
This function is similar to AsyncJulia::init
except that it loads a custom system
image. A custom image can be generated with the PackageCompiler
package for Julia. The
main advantage of using a custom image over the default one is that it allows you to avoid
much of the compilation overhead often associated with Julia.
In addition to the common arguments to initialize the async runtime, you need to provide
julia_bindir
and image_path
. The first must be the absolute path to a directory that
contains a compatible Julia binary (eg ${JULIA_DIR}/bin
), the second must be either an
absolute or a relative path to a system image.
This function returns an error if either of the two paths doesn’t exist, if the
JULIA_NUM_THREADS
environment variable is set to a value smaller than 3 or some invalid
value, or if Julia has already been initialized. If the environment variable is not set
it’s set to auto
. See the [struct-level] documentation for more info about this
method’s arguments.
Safety: this method can race with other crates that try to initialize Julia at the same time.
pub async unsafe fn init_with_image_async<P, Q>(
max_n_tasks: usize,
channel_capacity: usize,
recv_timeout: Duration,
julia_bindir: P,
image_path: Q
) -> JlrsResult<(Self, JoinHandle<JlrsResult<()>>)> where
P: AsRef<Path> + Send + 'static,
Q: AsRef<Path> + Send + 'static,
pub async unsafe fn init_with_image_async<P, Q>(
max_n_tasks: usize,
channel_capacity: usize,
recv_timeout: Duration,
julia_bindir: P,
image_path: Q
) -> JlrsResult<(Self, JoinHandle<JlrsResult<()>>)> where
P: AsRef<Path> + Send + 'static,
Q: AsRef<Path> + Send + 'static,
This function is similar to AsyncJulia::init_async
except that it loads a custom
system image. A custom image can be generated with the PackageCompiler
package for
Julia. The main advantage of using a custom image over the default one is that it allows
you to avoid much of the compilation overhead often associated with Julia.
In addition to the common arguments to initialize the async runtime, you need to provide
julia_bindir
and image_path
. The first must be the absolute path to a directory that
contains a compatible Julia binary (eg ${JULIA_DIR}/bin
), the second must be either an
absolute or a relative path to a system image.
This function returns an error if either of the two paths doesn’t exist, if the
JULIA_NUM_THREADS
environment variable is set to a value smaller than 3 or some invalid
value, or if Julia has already been initialized. If the environment variable is not set
it’s set to auto
. See the [struct-level] documentation for more info about this
method’s arguments.
Safety: this method can race with other crates that try to initialize Julia at the same time.
pub async fn task<AT, R>(&self, task: AT, res_sender: R) where
AT: AsyncTask,
R: ResultSender<JlrsResult<AT::Output>>,
pub async fn task<AT, R>(&self, task: AT, res_sender: R) where
AT: AsyncTask,
R: ResultSender<JlrsResult<AT::Output>>,
Send a new task to the runtime, this method waits if there’s no room in the channel. This method takes two arguments, the task and the sending half of a channel which is used to send the result back after the task has completed.
pub fn try_task<AT, R>(&self, task: AT, res_sender: R) -> JlrsResult<()> where
AT: AsyncTask,
R: ResultSender<JlrsResult<AT::Output>>,
pub fn try_task<AT, R>(&self, task: AT, res_sender: R) -> JlrsResult<()> where
AT: AsyncTask,
R: ResultSender<JlrsResult<AT::Output>>,
Try to send a new task to the runtime, if there’s no room in the channel an error is returned immediately. This method takes two arguments, the task and the sending half of a channel which is used to send the result back after the task has completed.
pub async fn blocking_task<T, R, F>(&self, task: F, res_sender: R) where
for<'base> F: 'static + Send + Sync + FnOnce(Global<'base>, &mut GcFrame<'base, Async<'base>>) -> JlrsResult<T>,
R: ResultSender<JlrsResult<T>>,
T: Send + Sync + 'static,
pub async fn blocking_task<T, R, F>(&self, task: F, res_sender: R) where
for<'base> F: 'static + Send + Sync + FnOnce(Global<'base>, &mut GcFrame<'base, Async<'base>>) -> JlrsResult<T>,
R: ResultSender<JlrsResult<T>>,
T: Send + Sync + 'static,
Sends a blocking task to the async runtime, if there’s no room in the channel an error is
returned immediately. A blocking task is a closure that takes two arguments, a Global
and mutable reference to a GcFrame
, and must return a JlrsResult
whose inner type is
both Send
and Sync
. This task is executed as soon as possible and can’t call async
methods, so it block the runtime. The result of the closure is sent to res_sender
.
pub fn try_blocking_task<T, R, F>(
&self,
task: F,
res_sender: R
) -> JlrsResult<()> where
for<'base> F: 'static + Send + Sync + FnOnce(Global<'base>, &mut GcFrame<'base, Async<'base>>) -> JlrsResult<T>,
R: ResultSender<JlrsResult<T>>,
T: Send + Sync + 'static,
pub fn try_blocking_task<T, R, F>(
&self,
task: F,
res_sender: R
) -> JlrsResult<()> where
for<'base> F: 'static + Send + Sync + FnOnce(Global<'base>, &mut GcFrame<'base, Async<'base>>) -> JlrsResult<T>,
R: ResultSender<JlrsResult<T>>,
T: Send + Sync + 'static,
Sends a blocking task to the async runtime, this method waits if there’s no room in the
channel. A blocking task is a closure that takes two arguments, a Global
and mutable
reference to a GcFrame
, and must return a JlrsResult
whose inner type is both Send
and Sync
. This task is executed as soon as possible and can’t call async methods, so it
block the runtime. The result of the closure is sent to res_sender
.
pub async fn blocking_task_with_slots<T, R, F>(
&self,
task: F,
res_sender: R,
slots: usize
) where
for<'base> F: 'static + Send + Sync + FnOnce(Global<'base>, &mut GcFrame<'base, Async<'base>>) -> JlrsResult<T>,
R: ResultSender<JlrsResult<T>>,
T: Send + Sync + 'static,
pub async fn blocking_task_with_slots<T, R, F>(
&self,
task: F,
res_sender: R,
slots: usize
) where
for<'base> F: 'static + Send + Sync + FnOnce(Global<'base>, &mut GcFrame<'base, Async<'base>>) -> JlrsResult<T>,
R: ResultSender<JlrsResult<T>>,
T: Send + Sync + 'static,
Sends a blocking task to the async runtime, if there’s no room in the channel an error is
returned immediately. A blocking task is a closure that takes two arguments, a Global
and mutable reference to a GcFrame
, and must return a JlrsResult
whose inner type is
both Send
and Sync
. This task is executed as soon as possible and can’t call async
methods, so it block the runtime. The result of the closure is sent to res_sender
.
pub fn try_blocking_task_with_slots<T, R, F>(
&self,
task: F,
res_sender: R,
slots: usize
) -> JlrsResult<()> where
for<'base> F: 'static + Send + Sync + FnOnce(Global<'base>, &mut GcFrame<'base, Async<'base>>) -> JlrsResult<T>,
R: ResultSender<JlrsResult<T>>,
T: Send + Sync + 'static,
pub fn try_blocking_task_with_slots<T, R, F>(
&self,
task: F,
res_sender: R,
slots: usize
) -> JlrsResult<()> where
for<'base> F: 'static + Send + Sync + FnOnce(Global<'base>, &mut GcFrame<'base, Async<'base>>) -> JlrsResult<T>,
R: ResultSender<JlrsResult<T>>,
T: Send + Sync + 'static,
Sends a blocking task to the async runtime, this method waits if there’s no room in the
channel. A blocking task is a closure that takes two arguments, a Global
and mutable
reference to a GcFrame
, and must return a JlrsResult
whose inner type is both Send
and Sync
. This task is executed as soon as possible and can’t call async methods, so it
block the runtime. The result of the closure is sent to res_sender
.
pub async fn register_task<AT, R>(&self, res_sender: R) where
AT: AsyncTask,
R: ResultSender<JlrsResult<()>>,
pub async fn register_task<AT, R>(&self, res_sender: R) where
AT: AsyncTask,
R: ResultSender<JlrsResult<()>>,
Register a task, this method waits if there’s no room in the channel. This method takes one argument, the sending half of a channel which is used to send the result back after the registration has completed.
pub fn try_register_task<AT, R>(&self, res_sender: R) -> JlrsResult<()> where
AT: AsyncTask,
R: ResultSender<JlrsResult<()>>,
pub fn try_register_task<AT, R>(&self, res_sender: R) -> JlrsResult<()> where
AT: AsyncTask,
R: ResultSender<JlrsResult<()>>,
Try to register a task, if there’s no room in the channel an error is returned immediately. This method takes one argument, the sending half of a channel which is used to send the result back after the registration has completed.
pub async fn persistent<GT>(&self, task: GT) -> JlrsResult<PersistentHandle<GT>> where
GT: PersistentTask,
pub async fn persistent<GT>(&self, task: GT) -> JlrsResult<PersistentHandle<GT>> where
GT: PersistentTask,
Send a new persistent to the runtime, this method waits if there’s no room in the channel.
This method takes a single argument, the task. It returns after
PersistentTask::init
has been called, a PersistentHandle
to the task is
returned if this method completes successfully, and the error if it doesn’t.
pub fn try_persistent<GT>(&self, task: GT) -> JlrsResult<PersistentHandle<GT>> where
GT: PersistentTask,
pub fn try_persistent<GT>(&self, task: GT) -> JlrsResult<PersistentHandle<GT>> where
GT: PersistentTask,
Send a new persistent to the runtime, if there’s no room in the channel an error is
returned immediately. This method takes a single argument, the task. It returns after
PersistentTask::init
has been called, a PersistentHandle
to the task is
returned if this method completes successfully, and the error if it doesn’t.
pub async fn register_persistent<GT, R>(&self, res_sender: R) where
GT: PersistentTask,
R: ResultSender<JlrsResult<()>>,
pub async fn register_persistent<GT, R>(&self, res_sender: R) where
GT: PersistentTask,
R: ResultSender<JlrsResult<()>>,
Register a persistent, this method waits if there’s no room in the channel. This method takes one argument, the sending half of a channel which is used to send the result back after the registration has completed.
pub fn try_register_persistent<GT, R>(&self, res_sender: R) -> JlrsResult<()> where
GT: PersistentTask,
R: ResultSender<JlrsResult<()>>,
pub fn try_register_persistent<GT, R>(&self, res_sender: R) -> JlrsResult<()> where
GT: PersistentTask,
R: ResultSender<JlrsResult<()>>,
Try to register a persistent, if there’s no room in the channel an error is returned immediately. This method takes one argument, the sending half of a channel which is used to send the result back after the registration has completed.
Include a Julia file. This method waits until the call to Main.include
in Julia has been
completed. It returns an error if the path doesn’t exist or the call to Main.include
throws an exception.
Include a Julia file. This method waits until the call Main.include
in Julia has been
completed. It returns an error if the path doesn’t exist, the channel is full, or the
call to Main.include
throws an exception.
Enable or disable colored error messages originating from Julia. If this is enabled the
error message in JlrsError::Exception
can contain ANSI color codes. This feature is
disabled by default.
Enable or disable colored error messages originating from Julia. If this is enabled the
error message in JlrsError::Exception
can contain ANSI color codes. This feature is
disabled by default.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for AsyncJulia
impl Send for AsyncJulia
impl Sync for AsyncJulia
impl Unpin for AsyncJulia
impl UnwindSafe for AsyncJulia
Blanket Implementations
Mutably borrows from an owned value. Read more