Struct jlrs::extensions::multitask::AsyncJulia [−][src]
pub struct AsyncJulia<T, R> where
T: Send + Sync + 'static,
R: ReturnChannel<T = T>, { /* 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. The two generic type parameters T
and R
are the return type and return channel type respectively, which must be the same across
all different implementations of AsyncTask
that you use.
The easiest way to get started is to use T = Box<dyn Any + Send + Sync>
, the return channel
must implement the ReturnChannel
trait. This trait is implemented for Sender
from
async_std
and crossbeam_channel
.
All initialization methods share two arguments:
channel_capacity
: the capacity of the channel used to communicate with the runtime.process_events_ms
: to ensure the garbage collector can run and tasks that have yielded in Julia are rescheduled, events must be processed periodically when at least one task is running.
Implementations
pub unsafe fn init(
channel_capacity: usize,
process_events_ms: u64
) -> JlrsResult<(Self, ThreadHandle<JlrsResult<()>>)>
pub unsafe fn init(
channel_capacity: usize,
process_events_ms: u64
) -> JlrsResult<(Self, ThreadHandle<JlrsResult<()>>)>
Initialize Julia in a new thread.
This function will return an error if the JULIA_NUM_THREADS
environment variable is not
set or set to a value smaller than 3, or if Julia has already been initialized. It is
unsafe because this crate provides you with a way to execute arbitrary Julia code which
can’t be checked for correctness.
pub async unsafe fn init_async(
channel_capacity: usize,
process_events_ms: u64
) -> JlrsResult<(Self, AsyncStdHandle<JlrsResult<()>>)>
pub async unsafe fn init_async(
channel_capacity: usize,
process_events_ms: u64
) -> JlrsResult<(Self, AsyncStdHandle<JlrsResult<()>>)>
Initialize Julia as a blocking task.
This function will return an error if the JULIA_NUM_THREADS
environment variable is not
set or set to a value smaller than 3, or if Julia has already been initialized. It is
unsafe because this crate provides you with a way to execute arbitrary Julia code which
can’t be checked for correctness.
pub unsafe fn init_with_image<P, Q>(
channel_capacity: usize,
process_events_ms: u64,
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>(
channel_capacity: usize,
process_events_ms: u64,
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 will return an error if either of the two paths doesn’t exist, if the
JULIA_NUM_THREADS
environment variable is not set or set to a value smaller than 3, or
if Julia has already been initialized. It is unsafe because this crate provides you with
a way to execute arbitrary Julia code which can’t be checked for correctness.
pub async unsafe fn init_with_image_async<P, Q>(
channel_capacity: usize,
process_events_ms: u64,
julia_bindir: P,
image_path: Q
) -> JlrsResult<(Self, AsyncStdHandle<JlrsResult<()>>)> where
P: AsRef<Path> + Send + 'static,
Q: AsRef<Path> + Send + 'static,
pub async unsafe fn init_with_image_async<P, Q>(
channel_capacity: usize,
process_events_ms: u64,
julia_bindir: P,
image_path: Q
) -> JlrsResult<(Self, AsyncStdHandle<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 will return an error if either of the two paths doesn’t exist, if the
JULIA_NUM_THREADS
environment variable is not set or set to a value smaller than 3, or
if Julia has already been initialized. It is unsafe because this crate provides you with
a way to execute arbitrary Julia code which can’t be checked for correctness.
Send a new task to the runtime, this method waits until there’s room in the channel.
Try to send a new task to the runtime, if there’s no room in the channel an error is returned immediately.
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 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.
Trait Implementations
impl<T: Clone, R: Clone> Clone for AsyncJulia<T, R> where
T: Send + Sync + 'static,
R: ReturnChannel<T = T>,
impl<T: Clone, R: Clone> Clone for AsyncJulia<T, R> where
T: Send + Sync + 'static,
R: ReturnChannel<T = T>,
Auto Trait Implementations
impl<T, R> RefUnwindSafe for AsyncJulia<T, R>
impl<T, R> Send for AsyncJulia<T, R>
impl<T, R> Sync for AsyncJulia<T, R>
impl<T, R> Unpin for AsyncJulia<T, R>
impl<T, R> UnwindSafe for AsyncJulia<T, R>
Blanket Implementations
Mutably borrows from an owned value. Read more