chore: specified dependencies versions

This commit is contained in:
LongYinan 2021-11-02 20:36:34 +08:00
parent 9570899025
commit d36c303dec
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
29 changed files with 543 additions and 85 deletions

View file

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

View file

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

View file

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

View file

@ -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
View 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)
}