UNPKG

1.56 kBTypeScriptView Raw
1/** @module run */
2import { IClosable } from './IClosable';
3/**
4 * Interface for components that require explicit opening and closing.
5 *
6 * For components that perform opening on demand consider using
7 * [[IClosable]] interface instead.
8 *
9 * @see [[IOpenable]]
10 * @see [[Opener]]
11 *
12 * ### Example ###
13 *
14 * class MyPersistence implements IOpenable {
15 * private _client: any;
16 * ...
17 * public isOpen(): boolean {
18 * return this._client != null;
19 * }
20 *
21 * public open(correlationId: string, callback: (err: any) => void): void {
22 * if (this.isOpen()) {
23 * callback(null);
24 * return;
25 * }
26 * ...
27 * }
28 *
29 * public close(correlationId: string, callback: (err: any) => void): void {
30 * if (this._client != null) {
31 * this._client.close();
32 * this._client = null;
33 * }
34 * callback(null);
35 * }
36 *
37 * ...
38 * }
39 */
40export interface IOpenable extends IClosable {
41 /**
42 * Checks if the component is opened.
43 *
44 * @returns true if the component has been opened and false otherwise.
45 */
46 isOpen(): boolean;
47 /**
48 * Opens the component.
49 *
50 * @param correlationId (optional) transaction id to trace execution through call chain.
51 * @param callback callback function that receives error or null no errors occured.
52 */
53 open(correlationId: string, callback?: (err: any) => void): void;
54}