transgate
Version:
Agent-based task flow framework
50 lines (49 loc) • 1.68 kB
TypeScript
import { GateItem, InGate, OutGate } from '../gate/type';
export interface IAgent {
run(): Promise<void>;
}
/**
* Process an item read from Input Gate and write into Output Gate
*/
export declare class Agent<T extends GateItem, O extends OutGate<any> | {
[key: string]: OutGate<any>;
}> implements IAgent {
private ingate;
private outgate;
/**
* @param {InGate} ingate - Input gate
* @param {OutGate} outgate - Output gate or its map
*/
constructor(ingate: InGate<T>, outgate: O);
/**
* Processes should be defined before all transactions
*/
before(): Promise<void>;
/**
* Processes should be defined after all transactions
*/
after(): Promise<void>;
run(): Promise<void>;
/**
* Process main Promise function
* @param {object} item - read item
* @param {OutputGate} outgate - Output gate
* @return {object|array} written item(s). it is an array if output is plural. `undefined` is not written.
*/
main(item: T, outgate: O): Promise<any>;
private sendToOutgate;
/**
* Shorthand to create Agent
* @param {Gate} ingate - Input gate
* @param {Gate|Object<string, Gate>} outgate - Output gate or its map
* @param {Promise} main - Process main Promise function
* @return {Agent} created one
*/
static create(ingate: InGate<any>, outgate: any, main: (item: any, outgate: any) => Promise<any>): Agent<any, any>;
/**
* Start all agents
* @param {Agent} ...agents - Agent(s)
* @return {Promise} A Promise that resolves when all agents have done
*/
static all(...agents: IAgent[]): Promise<void>;
}