The wrapper of coroutine impelemented by typescript, including the generator executor and a simple promise implementation.
Usage please refer to ./demo.ts
.
npm test
npm run build
public constructor(private coroutine: Generator<any, T, any>)
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>
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
。
npm test
npm run build