fix(napi-derive): unsound behavior while using reference and async together
This commit is contained in:
parent
91890456da
commit
618d0f8046
8 changed files with 160 additions and 28 deletions
examples/napi
|
@ -247,6 +247,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
name: string␊
|
||||
constructor(name: string)␊
|
||||
getCount(): number␊
|
||||
getNameAsync(): Promise<string>␊
|
||||
}␊
|
||||
export type Blake2bHasher = Blake2BHasher␊
|
||||
/** Smoking test for type generation */␊
|
||||
|
|
Binary file not shown.
|
@ -206,6 +206,11 @@ test('class', (t) => {
|
|||
})
|
||||
})
|
||||
|
||||
test('async self in class', async (t) => {
|
||||
const b = new Bird('foo')
|
||||
t.is(await b.getNameAsync(), 'foo')
|
||||
})
|
||||
|
||||
test('class factory', (t) => {
|
||||
const duck = ClassWithFactory.withName('Default')
|
||||
t.is(duck.name, 'Default')
|
||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -237,6 +237,7 @@ export class Bird {
|
|||
name: string
|
||||
constructor(name: string)
|
||||
getCount(): number
|
||||
getNameAsync(): Promise<string>
|
||||
}
|
||||
export type Blake2bHasher = Blake2BHasher
|
||||
/** Smoking test for type generation */
|
||||
|
|
|
@ -123,6 +123,12 @@ impl Bird {
|
|||
pub fn get_count(&self) -> u32 {
|
||||
1234
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub async fn get_name_async(&self) -> &str {
|
||||
tokio::time::sleep(std::time::Duration::new(1, 0)).await;
|
||||
self.name.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
/// Smoking test for type generation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue