Skip to content

Commit 29b9653

Browse files
committed
refactor: Avoid Option wrapping when calling rust -> gluon
1 parent 9b8075e commit 29b9653

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

vm/src/api/function.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ impl<T, $($args,)* R> Function<T, fn($($args),*) -> R>
384384
{
385385
#[allow(non_snake_case)]
386386
pub fn call(&mut self $(, $args: $args)*) -> Result<R> {
387-
$(
388-
let mut $args = Some($args);
389-
)*
390-
block_on_sync(future::poll_fn(|cx| {
391-
self.call_first(cx, $($args.take().unwrap()),*)
387+
block_on_sync(future::lazy(|cx| {
388+
match self.call_first(cx, $($args),*) {
389+
Poll::Ready(r) => r,
390+
Poll::Pending => Err(Error::Message("Unexpected async".into())).into(),
391+
}
392392
}))
393393
}
394394

@@ -431,10 +431,7 @@ impl<T, $($args,)* R> Function<T, fn($($args),*) -> R>
431431
) -> Result<R>
432432
{
433433
use crate::thread::Execute;
434-
$(
435-
let mut $args = Some($args);
436-
)*
437-
match future::poll_fn(|cx| Poll::Ready(self.call_first(cx, $($args.take().unwrap()),*))).await {
434+
match future::lazy(|cx| self.call_first(cx, $($args),*)).await {
438435
Poll::Ready(result) => result,
439436
Poll::Pending => {
440437
let vm = self.value.vm().root_thread();

0 commit comments

Comments
 (0)