strong-tie/inbound-calls
0
1import { EventEmitter } from 'events'2import * as workerThreads from 'worker_threads'3 4interface ThreadStreamOptions {5 /**6 * The size (in bytes) of the buffer.7 * Must be greater than 4 (i.e. it must at least fit a 4-byte utf-8 char).8 * 9 * Default: `4 * 1024 * 1024` = `4194304`10 */11 bufferSize?: number,12 /**13 * The path to the Worker's main script or module.14 * Must be either an absolute path or a relative path (i.e. relative to the current working directory) starting with ./ or ../, or a WHATWG URL object using file: or data: protocol.15 * When using a data: URL, the data is interpreted based on MIME type using the ECMAScript module loader.16 * 17 * {@link workerThreads.Worker()}18 */19 filename: string | URL,20 /**21 * If `true`, write data synchronously; otherwise write data asynchronously.22 * 23 * Default: `false`.24 */25 sync?: boolean,26 /**27 * {@link workerThreads.WorkerOptions.workerData}28 * 29 * Default: `{}`30 */31 workerData?: any,32 /**33 * {@link workerThreads.WorkerOptions}34 * 35 * Default: `{}`36 */37 workerOpts?: workerThreads.WorkerOptions38}39 40 41declare class ThreadStream extends EventEmitter {42 /**43 * @param {ThreadStreamOptions} opts 44 */45 constructor(opts: ThreadStreamOptions)46 /**47 * Write some data to the stream.48 * 49 * **Please note that this method should not throw an {Error} if something goes wrong but emit an error event.**50 * @param {string} data data to write.51 * @returns {boolean} false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data or if it fails to write; otherwise true.52 */53 write(data: string): boolean54 /**55 * Signal that no more data will be written.56 * 57 * **Please note that this method should not throw an {Error} if something goes wrong but emit an error event.**58 * 59 * Calling the {@link write()} method after calling {@link end()} will emit an error.60 */61 end(): void62 /**63 * Flush the stream synchronously.64 * This method should be called in the shutdown phase to make sure that all data has been flushed.65 * 66 * **Please note that this method will throw an {Error} if something goes wrong.**67 * 68 * @throws {Error} if the stream is already flushing, if it fails to flush or if it takes more than 10 seconds to flush.69 */70 flushSync(): void71 /**72 * Synchronously calls each of the listeners registered for the event named`eventName`, in the order they were registered, passing the supplied arguments73 * to each.74 *75 * @param eventName the name of the event.76 * @param args the arguments to be passed to the event handlers.77 * @returns {boolean} `true` if the event had listeners, `false` otherwise.78 */79 emit(eventName: string | symbol, ...args: any[]): boolean;80 81 /**82 * Post a message to the Worker with specified data and an optional list of transferable objects.83 *84 * @param eventName the name of the event, specifically 'message'.85 * @param message message data to be sent to the Worker.86 * @param transferList an optional list of transferable objects to be transferred to the Worker context.87 * @returns {boolean} true if the event had listeners, false otherwise.88 */89 emit(eventName: 'message', message: any, transferList?: workerThreads.TransferListItem[]): boolean90}91 92export = ThreadStream;93 