fix(napi-derive): unsound behavior while using reference and async together

This commit is contained in:
Jacob Kiesel 2022-11-21 09:17:19 -07:00 committed by GitHub
parent 91890456da
commit 618d0f8046
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 160 additions and 28 deletions

View file

@ -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 */␊

View file

@ -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')

View file

@ -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 */

View file

@ -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