denoland / deno_bindgen

Write high-level Deno FFI libraries in Rust.
MIT License
274 stars 28 forks source link

async codegen type decls missing & no promise resolving of number/void types #109

Closed ross-weir closed 10 months ago

ross-weir commented 1 year ago

Using deno_bindgen==0.7.0 I'm facing some issues with non_blocking / async codegen.

Given the following defs:

#[deno_bindgen(non_blocking)]
pub fn test_str_async() -> String {
    "test".to_string()
}

#[deno_bindgen(non_blocking)]
pub fn test_u32_async() -> u32 {
    1
}

#[deno_bindgen(non_blocking)]
pub fn test_void_async() {}

Generates the following TS:

...

const _lib = await prepare(opts, {
  test_str_async: { parameters: [], result: "pointer", nonblocking: true },
  test_u32_async: { parameters: [], result: "u32", nonblocking: true },
  test_void_async: { parameters: [], result: "void", nonblocking: true },
})

export function test_str_async() {
  let rawResult = _lib.symbols.test_str_async()
  const result = rawResult.then(readPointer)
  return result.then(decode)
}
export function test_u32_async() {
  let rawResult = _lib.symbols.test_u32_async()
  const result = rawResult
  return result
}
export function test_void_async() {
  let rawResult = _lib.symbols.test_void_async()
  const result = rawResult
  return result
}

Some issues: