UNPKG

1.26 kBTypeScriptView Raw
1/** @module run */
2import { Parameters } from './Parameters';
3/**
4 * Interface for components that can be called to execute work.
5 *
6 * @see [[Executor]]
7 * @see [[INotifiable]]
8 * @see [[Parameters]]
9 *
10 * ### Example ###
11 *
12 * class EchoComponent implements IExecutable {
13 * ...
14 * public execute(correlationId: string, args: Parameters, callback: (err: any, result: any) => void): void {
15 * let result = args.getAsObject("message");
16 * callback(null, result);
17 * }
18 * }
19 *
20 * let echo = new EchoComponent();
21 * let message = "Test";
22 * echo.execute("123", Parameters.fromTuples("message", message),
23 * (err, result) => {
24 * console.log("Request: " + message + " Response: " + result);
25 * }
26 * );
27 */
28export interface IExecutable {
29 /**
30 * Executes component with arguments and receives execution result.
31 *
32 * @param correlationId (optional) transaction id to trace execution through call chain.
33 * @param args execution arguments.
34 * @param callback callback function that receives execution result or error.
35 */
36 execute(correlationId: string, args: Parameters, callback: (err: any, result: any) => void): void;
37}