Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno FFI: Support async function calls #11673

Closed
rracariu opened this issue Aug 12, 2021 · 5 comments
Closed

Deno FFI: Support async function calls #11673

rracariu opened this issue Aug 12, 2021 · 5 comments

Comments

@rracariu
Copy link

The FFI interface should allow calling functions asynchronously.

This would be necessary as plugin interface allowed defining such async Ops, and in general this would be required in most cases where calling an function might block the event loop.

Some initial ideas in #11152 (comment)

@bartlomieju
Copy link
Member

@piscisaureus do you have an opinion on this one? I think we might somehow shim it using https://github.com/littledivy/deno_bindgen

@littledivy
Copy link
Member

Non blocking was implemented in 1.15. https://deno.land/[email protected]/runtime/ffi_api#non-blocking-ffi

btw here's how to use it with deno_bindgen:

// src/lib.rs
#[deno_bindgen(non_blocking)]
fn sleep(ms: u64) {
  let duration = std::time::Duration::from_millis(ms);
  std::thread::sleep(duration);
}
// main.ts
import { sleep } from "./bindings/bindings.ts";
await sleep(100);

@bartlomieju
Copy link
Member

@rracariu does the non blocking option solve the issue for you?

@rracariu
Copy link
Author

rracariu commented Nov 4, 2021

Yes, it does.

@rracariu rracariu closed this as completed Nov 4, 2021
@ghost
Copy link

ghost commented Mar 11, 2023

Is there any way to use 'await' inside a non_blocking async ffi call? for example boiler plate mongo db connection here:

let options = ClientOptions::parse_with_resolver_config(&db_url_tls, ResolverConfig::cloudflare()).await.unwrap();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants