index.js.flow 846 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// @flow

opaque type Next = Function | void;
opaque type Yield = mixed;

export type Gensync<Args, Return> = {
  (...args: Args): Handler<Return>,
  sync(...args: Args): Return,
  async(...args: Args): Promise<Return>,
  // ...args: [...Args, Callback]
  errback(...args: any[]): void,
};

export type Handler<Return> = Generator<Yield, Return, Next>;
export type Options<Args, Return> = {
  sync(...args: Args): Return,
  arity?: number,
  name?: string,
} & (
  | { async?: (...args: Args) => Promise<Return> }
  // ...args: [...Args, Callback]
  | { errback(...args: any[]): void }
);

declare module.exports: {
  <Args, Return>(
    Options<Args, Return> | ((...args: Args) => Handler<Return>)
  ): Gensync<Args, Return>,

  all<Return>(Array<Handler<Return>>): Handler<Return[]>,
  race<Return>(Array<Handler<Return>>): Handler<Return>,
};