fix(napi-derive): missing move in async fn
This commit is contained in:
parent
c2c5887ea4
commit
785388ae40
6 changed files with 15 additions and 1 deletions
|
@ -33,7 +33,7 @@ impl TryToTokens for NapiFn {
|
||||||
quote! { Ok(#receiver(#(#arg_names),*).await) }
|
quote! { Ok(#receiver(#(#arg_names),*).await) }
|
||||||
};
|
};
|
||||||
quote! {
|
quote! {
|
||||||
execute_tokio_future(env, async { #call }, |env, #receiver_ret_name| {
|
execute_tokio_future(env, async move { #call }, |env, #receiver_ret_name| {
|
||||||
#ret
|
#ret
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
export function getNums(): Array<number>␊
|
export function getNums(): Array<number>␊
|
||||||
export function sumNums(nums: Array<number>): number␊
|
export function sumNums(nums: Array<number>): number␊
|
||||||
export function readFileAsync(path: string): Promise<Buffer>␊
|
export function readFileAsync(path: string): Promise<Buffer>␊
|
||||||
|
export function asyncMultiTwo(arg: number): Promise<number>␊
|
||||||
export function getCwd(callback: (arg0: string) => void): void␊
|
export function getCwd(callback: (arg0: string) => void): void␊
|
||||||
export function readFile(callback: (arg0: Error | undefined, arg1: string | null) => void): void␊
|
export function readFile(callback: (arg0: Error | undefined, arg1: string | null) => void): void␊
|
||||||
export function eitherStringOrNumber(input: string | number): number␊
|
export function eitherStringOrNumber(input: string | number): number␊
|
||||||
|
|
Binary file not shown.
|
@ -34,6 +34,7 @@ import {
|
||||||
either4,
|
either4,
|
||||||
withoutAbortController,
|
withoutAbortController,
|
||||||
withAbortController,
|
withAbortController,
|
||||||
|
asyncMultiTwo,
|
||||||
} from '../'
|
} from '../'
|
||||||
|
|
||||||
test('number', (t) => {
|
test('number', (t) => {
|
||||||
|
@ -163,6 +164,10 @@ test('async', async (t) => {
|
||||||
await t.throwsAsync(() => readFileAsync('some_nonexist_path.file'))
|
await t.throwsAsync(() => readFileAsync('some_nonexist_path.file'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('async move', async (t) => {
|
||||||
|
t.is(await asyncMultiTwo(2), 4)
|
||||||
|
})
|
||||||
|
|
||||||
test('either', (t) => {
|
test('either', (t) => {
|
||||||
t.is(eitherStringOrNumber(2), 2)
|
t.is(eitherStringOrNumber(2), 2)
|
||||||
t.is(eitherStringOrNumber('hello'), 'hello'.length)
|
t.is(eitherStringOrNumber('hello'), 'hello'.length)
|
||||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -2,6 +2,7 @@ export function getWords(): Array<string>
|
||||||
export function getNums(): Array<number>
|
export function getNums(): Array<number>
|
||||||
export function sumNums(nums: Array<number>): number
|
export function sumNums(nums: Array<number>): number
|
||||||
export function readFileAsync(path: string): Promise<Buffer>
|
export function readFileAsync(path: string): Promise<Buffer>
|
||||||
|
export function asyncMultiTwo(arg: number): Promise<number>
|
||||||
export function getCwd(callback: (arg0: string) => void): void
|
export function getCwd(callback: (arg0: string) => void): void
|
||||||
export function readFile(callback: (arg0: Error | undefined, arg1: string | null) => void): void
|
export function readFile(callback: (arg0: Error | undefined, arg1: string | null) => void): void
|
||||||
export function eitherStringOrNumber(input: string | number): number
|
export function eitherStringOrNumber(input: string | number): number
|
||||||
|
|
|
@ -14,3 +14,10 @@ async fn read_file_async(path: String) -> Result<Buffer> {
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
async fn async_multi_two(arg: u32) -> Result<u32> {
|
||||||
|
tokio::task::spawn(async move { Ok(arg * 2) })
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue