Skip to content

适配 Promise/Thunk 的上层协程调度器封装

Notifications You must be signed in to change notification settings

Drincann/js-coroutine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

适配 Promise/Thunk 的上层协程调度器封装

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published