ChildProcessWorker.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. /// <reference types="node" />
  8. import { WorkerInterface, ChildMessage, OnEnd, OnStart, WorkerOptions, ParentMessage } from '../types';
  9. /**
  10. * This class wraps the child process and provides a nice interface to
  11. * communicate with. It takes care of:
  12. *
  13. * - Re-spawning the process if it dies.
  14. * - Queues calls while the worker is busy.
  15. * - Re-sends the requests if the worker blew up.
  16. *
  17. * The reason for queueing them here (since childProcess.send also has an
  18. * internal queue) is because the worker could be doing asynchronous work, and
  19. * this would lead to the child process to read its receiving buffer and start a
  20. * second call. By queueing calls here, we don't send the next call to the
  21. * children until we receive the result of the previous one.
  22. *
  23. * As soon as a request starts to be processed by a worker, its "processed"
  24. * field is changed to "true", so that other workers which might encounter the
  25. * same call skip it.
  26. */
  27. export default class ChildProcessWorker implements WorkerInterface {
  28. private _child;
  29. private _options;
  30. private _onProcessEnd;
  31. private _fakeStream;
  32. private _request;
  33. private _retries;
  34. private _stderr;
  35. private _stdout;
  36. constructor(options: WorkerOptions);
  37. initialize(): void;
  38. private _shutdown;
  39. onMessage(response: ParentMessage): void;
  40. onExit(exitCode: number): void;
  41. send(request: ChildMessage, onProcessStart: OnStart, onProcessEnd: OnEnd): void;
  42. getWorkerId(): number;
  43. getStdout(): NodeJS.ReadableStream | null;
  44. getStderr(): NodeJS.ReadableStream | null;
  45. private _getFakeStream;
  46. }
  47. //# sourceMappingURL=ChildProcessWorker.d.ts.map