stream#finished TypeScript Examples

The following examples show how to use stream#finished. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: context.ts    From flatend with MIT License 6 votes vote down vote up
constructor(
    provider: Provider,
    stream: Stream,
    headers: { [key: string]: string }
  ) {
    super();

    this._provider = provider;
    this._stream = stream;
    this.headers = headers;

    // pipe stream body to context

    setImmediate(async () => {
      for await (const frame of this._stream.body) {
        this.push(frame);
      }
      this.push(null);
    });

    // write stream eof when stream writable is closed

    setImmediate(async () => {
      await util.promisify(finished)(this, { readable: false });

      await this._writeHeader();

      const payload = new DataPacket(this._stream.id, Buffer.of()).encode();
      await this._provider.write(
        this._provider.rpc.message(
          0,
          Buffer.concat([Buffer.of(Opcode.Data), payload])
        )
      );
    });
  }
Example #2
Source File: Stream.ts    From vscode-file-downloader with MIT License 5 votes vote down vote up
finishedAsync = promisify(finished)