UNPKG

4.54 kBTypeScriptView Raw
1import { DisposableDelegate } from '@lumino/disposable';
2import * as Kernel from './kernel';
3import * as KernelMessage from './messages';
4/**
5 * Implementation of a kernel future.
6 *
7 * If a reply is expected, the Future is considered done when both a `reply`
8 * message and an `idle` iopub status message have been received. Otherwise, it
9 * is considered done when the `idle` status is received.
10 *
11 */
12export declare abstract class KernelFutureHandler<REQUEST extends KernelMessage.IShellControlMessage, REPLY extends KernelMessage.IShellControlMessage> extends DisposableDelegate implements Kernel.IFuture<REQUEST, REPLY> {
13 /**
14 * Construct a new KernelFutureHandler.
15 */
16 constructor(cb: () => void, msg: REQUEST, expectReply: boolean, disposeOnDone: boolean, kernel: Kernel.IKernelConnection);
17 /**
18 * Get the original outgoing message.
19 */
20 get msg(): REQUEST;
21 /**
22 * A promise that resolves when the future is done.
23 */
24 get done(): Promise<REPLY>;
25 /**
26 * Get the reply handler.
27 */
28 get onReply(): (msg: REPLY) => void | PromiseLike<void>;
29 /**
30 * Set the reply handler.
31 */
32 set onReply(cb: (msg: REPLY) => void | PromiseLike<void>);
33 /**
34 * Get the iopub handler.
35 */
36 get onIOPub(): (msg: KernelMessage.IIOPubMessage) => void | PromiseLike<void>;
37 /**
38 * Set the iopub handler.
39 */
40 set onIOPub(cb: (msg: KernelMessage.IIOPubMessage) => void | PromiseLike<void>);
41 /**
42 * Get the stdin handler.
43 */
44 get onStdin(): (msg: KernelMessage.IStdinMessage) => void | PromiseLike<void>;
45 /**
46 * Set the stdin handler.
47 */
48 set onStdin(cb: (msg: KernelMessage.IStdinMessage) => void | PromiseLike<void>);
49 /**
50 * Register hook for IOPub messages.
51 *
52 * @param hook - The callback invoked for an IOPub message.
53 *
54 * #### Notes
55 * The IOPub hook system allows you to preempt the handlers for IOPub
56 * messages handled by the future.
57 *
58 * The most recently registered hook is run first. A hook can return a
59 * boolean or a promise to a boolean, in which case all kernel message
60 * processing pauses until the promise is fulfilled. If a hook return value
61 * resolves to false, any later hooks will not run and the function will
62 * return a promise resolving to false. If a hook throws an error, the error
63 * is logged to the console and the next hook is run. If a hook is
64 * registered during the hook processing, it will not run until the next
65 * message. If a hook is removed during the hook processing, it will be
66 * deactivated immediately.
67 */
68 registerMessageHook(hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>): void;
69 /**
70 * Remove a hook for IOPub messages.
71 *
72 * @param hook - The hook to remove.
73 *
74 * #### Notes
75 * If a hook is removed during the hook processing, it will be deactivated immediately.
76 */
77 removeMessageHook(hook: (msg: KernelMessage.IIOPubMessage) => boolean | PromiseLike<boolean>): void;
78 /**
79 * Send an `input_reply` message.
80 */
81 sendInputReply(content: KernelMessage.IInputReplyMsg['content'], parent_header: KernelMessage.IInputReplyMsg['parent_header']): void;
82 /**
83 * Dispose and unregister the future.
84 */
85 dispose(): void;
86 /**
87 * Handle an incoming kernel message.
88 */
89 handleMsg(msg: KernelMessage.IMessage): Promise<void>;
90 private _handleReply;
91 private _handleStdin;
92 private _handleIOPub;
93 private _handleDone;
94 /**
95 * Test whether the given future flag is set.
96 */
97 private _testFlag;
98 /**
99 * Set the given future flag.
100 */
101 private _setFlag;
102 private _msg;
103 private _status;
104 private _stdin;
105 private _iopub;
106 private _reply;
107 private _done;
108 private _replyMsg;
109 private _hooks;
110 private _disposeOnDone;
111 private _kernel;
112}
113export declare class KernelControlFutureHandler<REQUEST extends KernelMessage.IControlMessage = KernelMessage.IControlMessage, REPLY extends KernelMessage.IControlMessage = KernelMessage.IControlMessage> extends KernelFutureHandler<REQUEST, REPLY> implements Kernel.IControlFuture<REQUEST, REPLY> {
114}
115export declare class KernelShellFutureHandler<REQUEST extends KernelMessage.IShellMessage = KernelMessage.IShellMessage, REPLY extends KernelMessage.IShellMessage = KernelMessage.IShellMessage> extends KernelFutureHandler<REQUEST, REPLY> implements Kernel.IShellFuture<REQUEST, REPLY> {
116}