packages/then-pug/lib/index.js
function (locals) {
    var stream = new ReadableStream();
    
    // streaming will be set to false whenever there is back-pressure
    var streaming = false;

    function release() {
      streaming = true;
    }

    // make sure _read is always implemented
    stream._read = release;

    // then-yield unwrap function
    // which implements the backpressure pause mechanism
    function unwrap(value) {
      if (streaming) return value;
      return new Promise(function (resolve) {
        stream._read = function () {
          release();
          this._read = release;
          resolve(value);
        }
      });
    }

    var template = fn(locals, runtime, {
      push: function () {
        for (var i = 0; i < arguments.length; i++)
          if (!stream.push(arguments[i].toString())) streaming = false;
      }
    });

    // call our function, setting `streaming` to `false` whenever
    // the buffer is full and there is back-pressure
    var result = ty.spawn(template, Promise.resolve, unwrap);

    // once the function completes, we end the stream by pushing `null`
    if (result)
      result.then(stream.push.bind(stream, null), function (err) {
        stream.emit('error', err);
        stream.push(null);
      });
    else
      stream.push(null);

    return stream;
  }
function (locals) {
    var stream = new ReadableStream();
    
    // streaming will be set to false whenever there is back-pressure
    var streaming = false;

    function release() {
      streaming = true;
    }

    // make sure _read is always implemented
    stream._read = release;

    // then-yield unwrap function
    // which implements the backpressure pause mechanism
    function unwrap(value) {
      if (streaming) return value;
      return new Promise(function (resolve) {
        stream._read = function () {
          release();
          this._read = release;
          resolve(value);
        }
      });
    }

    var template = fn(locals, runtime, {
      push: function () {
        for (var i = 0; i < arguments.length; i++)
          if (!stream.push(arguments[i].toString())) streaming = false;
      }
    });

    // call our function, setting `streaming` to `false` whenever
    // the buffer is full and there is back-pressure
    var result = ty.spawn(template, Promise.resolve, unwrap);

    // once the function completes, we end the stream by pushing `null`
    if (result)
      result.then(stream.push.bind(stream, null), function (err) {
        stream.emit('error', err);
        stream.push(null);
      });
    else
      stream.push(null);

    return stream;
  }
function ( locals ) { var stream = new ReadableStream ( ) ; // streaming will be set to false whenever there is back-pressure var streaming = false ; function release ( ) { streaming = true ; } // make sure _read is always implemented stream . _read = release ; // then-yield unwrap function // which implements the backpressure pause mechanism function unwrap ( value ) { if ( streaming ) return value ; return new Promise ( function ( resolve ) { stream . _read = function ( ) { release ( ) ; this . _read = release ; resolve ( value ) ; } } ) ; } var template = fn ( locals , runtime , { push : function ( ) { for ( var i = 0 ; i < arguments . length ; i ++ ) if ( ! stream . push ( arguments [ i ] . toString ( ) ) ) streaming = false ; } } ) ; // call our function, setting `streaming` to `false` whenever // the buffer is full and there is back-pressure var result = ty . spawn ( template , Promise . resolve , unwrap ) ; // once the function completes, we end the stream by pushing `null` if ( result ) result . then ( stream . push . bind ( stream , null ) , function ( err ) { stream . emit ( 'error' , err ) ; stream . push ( null ) ; } ) ; else stream . push ( null ) ; return stream ; }
convert it to a function that takes `locals` and returns a readable stream
convert it to a function that takes locals and returns a readable stream