use std::future::Future;
use super::Call;
use crate::{
args::Values,
async_util::future::JuliaFuture,
data::managed::{erase_scope_lifetime, module::JlrsCore, named_tuple::NamedTuple},
error::JuliaResult,
memory::target::frame::AsyncGcFrame,
prelude::Value,
private::Private,
};
pub trait CallAsync<'data>: Call<'data> {
unsafe fn call_async<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> impl Future<Output = JuliaResult<'target, 'data>>
where
V: Values<'value, 'data, N>;
unsafe fn call_async_kw<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
kwargs: NamedTuple<'_, 'data>,
) -> impl Future<Output = JuliaResult<'target, 'data>>
where
V: Values<'value, 'data, N>;
unsafe fn schedule_async<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>;
unsafe fn schedule_async_kw<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>;
unsafe fn call_async_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> impl Future<Output = JuliaResult<'target, 'data>>
where
V: Values<'value, 'data, N>;
unsafe fn call_async_kw_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
kwargs: NamedTuple<'_, 'data>,
) -> impl Future<Output = JuliaResult<'target, 'data>>
where
V: Values<'value, 'data, N>;
unsafe fn schedule_async_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>;
unsafe fn schedule_async_kw_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>;
}
impl<'data> CallAsync<'data> for Value<'_, 'data> {
#[inline]
async unsafe fn call_async<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data>
where
V: Values<'value, 'data, N>,
{
unsafe { JuliaFuture::new(frame, erase_scope_lifetime(self), args).await }
}
#[inline]
async unsafe fn call_async_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data>
where
V: Values<'value, 'data, N>,
{
unsafe { JuliaFuture::new_interactive(frame, erase_scope_lifetime(self), args).await }
}
#[inline]
unsafe fn schedule_async_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>,
{
unsafe {
let args = args.into_extended_with_start([erase_scope_lifetime(self)], Private);
JlrsCore::interactive_call(&frame).call(&mut *frame, args.as_ref())
}
}
#[inline]
unsafe fn schedule_async<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>,
{
unsafe {
let args = args.into_extended_with_start([erase_scope_lifetime(self)], Private);
let task = JlrsCore::async_call(&frame).call(&mut *frame, args.as_ref());
match task {
Ok(t) => Ok(t),
Err(e) => Err(e),
}
}
}
#[inline]
async unsafe fn call_async_kw<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data>
where
V: Values<'value, 'data, N>,
{
JuliaFuture::new_with_keywords(frame, self, args, kwargs).await
}
#[inline]
unsafe fn schedule_async_kw<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>,
{
unsafe {
let args = args.into_extended_with_start([erase_scope_lifetime(self)], Private);
JlrsCore::async_call(&frame).call_kw(&mut *frame, args.as_ref(), kwargs)
}
}
#[inline]
async unsafe fn call_async_kw_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data>
where
V: Values<'value, 'data, N>,
{
JuliaFuture::new_interactive_with_keywords(frame, self, args, kwargs).await
}
#[inline]
unsafe fn schedule_async_kw_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>,
{
unsafe {
let args = args.into_extended_with_start([erase_scope_lifetime(self)], Private);
JlrsCore::interactive_call(&frame).call_kw(&mut *frame, args.as_ref(), kwargs)
}
}
}
#[allow(deprecated)]
impl<'data> CallAsync<'data> for super::WithKeywords<'_, 'data> {
#[inline]
async unsafe fn call_async<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data>
where
V: Values<'value, 'data, N>,
{
JuliaFuture::new_with_keywords(frame, self.function(), args, self.keywords()).await
}
#[inline]
async unsafe fn call_async_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data>
where
V: Values<'value, 'data, N>,
{
JuliaFuture::new_interactive_with_keywords(frame, self.function(), args, self.keywords())
.await
}
#[inline]
unsafe fn schedule_async_interactive<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>,
{
unsafe {
let args =
args.into_extended_with_start([erase_scope_lifetime(self.function())], Private);
JlrsCore::interactive_call(&frame).call_kw(&mut *frame, args.as_ref(), self.keywords())
}
}
#[inline]
unsafe fn schedule_async<'target, 'value, V, const N: usize>(
self,
frame: &mut AsyncGcFrame<'target>,
args: V,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>,
{
unsafe {
let args =
args.into_extended_with_start([erase_scope_lifetime(self.function())], Private);
JlrsCore::async_call(&frame).call_kw(&mut *frame, args.as_ref(), self.keywords())
}
}
async unsafe fn call_async_kw<'target, 'value, V, const N: usize>(
self,
_frame: &mut AsyncGcFrame<'target>,
_args: V,
_kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data>
where
V: Values<'value, 'data, N>,
{
unimplemented!("WithKeywords cannot take additional keyword arguments")
}
unsafe fn schedule_async_kw<'target, 'value, V, const N: usize>(
self,
_frame: &mut AsyncGcFrame<'target>,
_args: V,
_kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>,
{
unimplemented!("WithKeywords cannot take additional keyword arguments")
}
async unsafe fn call_async_kw_interactive<'target, 'value, V, const N: usize>(
self,
_frame: &mut AsyncGcFrame<'target>,
_args: V,
_kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data>
where
V: Values<'value, 'data, N>,
{
unimplemented!("WithKeywords cannot take additional keyword arguments")
}
unsafe fn schedule_async_kw_interactive<'target, 'value, V, const N: usize>(
self,
_frame: &mut AsyncGcFrame<'target>,
_args: V,
_kwargs: NamedTuple<'_, 'data>,
) -> JuliaResult<'target, 'data, Value<'target, 'data>>
where
V: Values<'value, 'data, N>,
{
unimplemented!("WithKeywords cannot take additional keyword arguments")
}
}