Skip to content

Latest commit

 

History

History
79 lines (55 loc) · 1.2 KB

README.md

File metadata and controls

79 lines (55 loc) · 1.2 KB

js-coroutine

chinese version

The wrapper of coroutine impelemented by typescript, including the generator executor and a simple promise implementation.

Usage please refer to ./demo.ts.

test

npm test

build

npm run build

API

Coroutine<T> extends MPromise<T>

public constructor(private coroutine: Generator<any, T, any>)

MPromise<T>

public constructor(
  resolver: (
    resolve: (value: MPromise<T> | T) => void,
    reject: (error: any) => void,
  ) => void
)
public then<NextPromiseRT>(
  onFulfilled?: (value: T) => MPromise<NextPromiseRT> | null | undefined | void,
  onRejected?: (error: any) => MPromise<NextPromiseRT> | null | undefined | void,
): MPromise<NextPromiseRT> 

Thunk<T>

public static toThunk<T>(
  asyncFn: (
    ...argsAndCallback: (any | ThunkCallback<T>)[]
  ) => void
): (...args: any[]) => Thunk<T>
public static isThunk(value: any): value is Thunk

TypeScript 实现的协程包装器,包含生成器执行器和简单的 Promise 实现。

API 请参考示例 ./demo.ts

test

npm test

build

npm run build