chore: specified dependencies versions
This commit is contained in:
parent
9570899025
commit
d36c303dec
29 changed files with 543 additions and 85 deletions
examples/napi
|
@ -42,6 +42,8 @@ Generated by [AVA](https://avajs.dev).
|
|||
export function concatStr(mutS: string): string␊
|
||||
export function concatUtf16(s: string): string␊
|
||||
export function concatLatin1(s: string): string␊
|
||||
export function withoutAbortController(a: number, b: number): Promise<number>␊
|
||||
export function withAbortController(a: number, b: number, ctrl: AbortController): Promise<number>␊
|
||||
export function getBuffer(): Buffer␊
|
||||
export class Animal {␊
|
||||
readonly kind: Kind␊
|
||||
|
|
Binary file not shown.
|
@ -30,6 +30,8 @@ import {
|
|||
returnEither,
|
||||
either3,
|
||||
either4,
|
||||
withoutAbortController,
|
||||
withAbortController,
|
||||
} from '../'
|
||||
|
||||
test('number', (t) => {
|
||||
|
@ -160,3 +162,19 @@ test('either4', (t) => {
|
|||
t.is(either4({ v: 1 }), 1)
|
||||
t.is(either4({ v: 'world' }), 'world'.length)
|
||||
})
|
||||
|
||||
test('async task without abort controller', async (t) => {
|
||||
t.is(await withoutAbortController(1, 2), 3)
|
||||
})
|
||||
|
||||
test('async task with abort controller', async (t) => {
|
||||
const ctrl = new AbortController()
|
||||
const promise = withAbortController(1, 2, ctrl)
|
||||
try {
|
||||
ctrl.abort()
|
||||
await promise
|
||||
t.fail('Should throw AbortError')
|
||||
} catch (err: unknown) {
|
||||
t.is((err as Error).message, 'AbortError')
|
||||
}
|
||||
})
|
||||
|
|
2
examples/napi/index.d.ts
vendored
2
examples/napi/index.d.ts
vendored
|
@ -32,6 +32,8 @@ export function contains(source: string, target: string): boolean
|
|||
export function concatStr(mutS: string): string
|
||||
export function concatUtf16(s: string): string
|
||||
export function concatLatin1(s: string): string
|
||||
export function withoutAbortController(a: number, b: number): Promise<number>
|
||||
export function withAbortController(a: number, b: number, ctrl: AbortController): Promise<number>
|
||||
export function getBuffer(): Buffer
|
||||
export class Animal {
|
||||
readonly kind: Kind
|
||||
|
|
|
@ -15,4 +15,5 @@ mod number;
|
|||
mod object;
|
||||
mod serde;
|
||||
mod string;
|
||||
mod task;
|
||||
mod typed_array;
|
||||
|
|
31
examples/napi/src/task.rs
Normal file
31
examples/napi/src/task.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use std::thread::sleep;
|
||||
|
||||
use napi::bindgen_prelude::*;
|
||||
use napi::Task;
|
||||
|
||||
struct DelaySum(u32, u32);
|
||||
|
||||
#[napi]
|
||||
impl Task for DelaySum {
|
||||
type Output = u32;
|
||||
type JsValue = u32;
|
||||
|
||||
fn compute(&mut self) -> Result<Self::Output> {
|
||||
sleep(std::time::Duration::from_secs(1));
|
||||
Ok(self.0 + self.1)
|
||||
}
|
||||
|
||||
fn resolve(self, _env: napi::Env, output: Self::Output) -> Result<Self::JsValue> {
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
|
||||
#[napi]
|
||||
fn without_abort_controller(a: u32, b: u32) -> AsyncTask<DelaySum> {
|
||||
AsyncTask::new(DelaySum(a, b))
|
||||
}
|
||||
|
||||
#[napi]
|
||||
fn with_abort_controller(a: u32, b: u32, ctrl: AsyncTaskAbortController) -> AsyncTask<DelaySum> {
|
||||
AsyncTask::with_abort_controller(DelaySum(a, b), ctrl)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue