Convert an async function to a Stream. When the function returns, its return value is enqueued to the stream.
@param {Function} fn
@returns {ReadableStream}
501972
function fromAsync(fn) {
  return new ReadableStream({
    pull: async controller => {
      try {
        controller.enqueue(await fn());
        controller.close();
      } catch(e) {
        controller.error(e);
      }
    }
  });
}
751564
function streamFromString(string) {
  const s = new stream.Readable();
  s.push(string);
  s.push(null);
  return s;
}
817301
function async(fn) {
  return function asynced(done) {
    var err, ret;
    try {
      ret = fn();
    } catch (e) {
      err = e;
    } finally {
      if (err) {
        done(err);
      } else {
        done(null, ret);
      }
    }
  };
}
1196183
public <V> Resources<V> transform(Function<T, V> fn) {
        return new Resources<>(
                resources.stream().map(fn).collect(Collectors.toList()),
                get_self(),
                pagination,
                Object.class
        ).withLinks(getLinks());
    }
732055
function readerToStream(reader) {
    return new ReadableStream({
        pull(controller) {
            return reader.read()
                .then(res => {
                    if (res.done) {
                        controller.close();
                    } else {
                        controller.enqueue(res.value);
                    }
                });
        },
        cancel(reason) { return reader.cancel(reason); }
    });
}
316224
async function* streamToGenerator(stream) {
  let promise;

  stream.on('data', data => promise.resolve(data));
  stream.once('end', () => promise.resolve(null));

  stream.on('error', error => {
    stream.removeAllListeners();
    promise.reject(error);
  });

  while (true) {
    promise = defer();

    yield promise;
  }
}
951106
function (file) {
      return $.Deferred(function (deferred) {
        $.extend(new FileReader(), {
          onload: function (e) {
            var dataURL = e.target.result;
            deferred.resolve(dataURL);
          },
          onerror: function () {
            deferred.reject(this);
          }
        }).readAsDataURL(file);
      }).promise();
    }
249798
function makeStream(conn) {
    return function stream(sql, options = { highWaterMark: 5 }) {
        return conn.query(sql).stream(options);
    };
}
992161
function( stream ){
			if( typeof stream == 'string' ){
				//if node.js create a writeable stream with this filename
			} else if( internals.hasProperties(stream,['write','end','writable'] && stream.writable)){
				this.objStream = stream;
			} else {
			}
			this._handleBeginSave();
		}
909494
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;
  }
496296
function streamFile(namespace, fileName) {
  var file;
  if (namespace) {
    file = path.join(namespace, fileName);
  } else {
    file = fileName;
  }
  var deferred = q.defer();
  var paramsStream = {
    Bucket: config.bucket,
    Key: file
  };
  try {
    var stream = awsClient.downloadStream(paramsStream);
    deferred.resolve(stream);
  } catch (error) {
    console.log(error);
    deferred.reject(error);
  }
  return deferred.promise;
}
1219984
async function convert(filename, options) {
    let file;
    if (filename) {
        file = fs.readFileSync(filename).toString();
    } else {
        file = await read_stdin();
    }
    try {
        file = JSON.parse(file);
    } catch {}
    let tbl = table(file);
    let view = tbl.view();
    let out;
    options.format = options.format || "arrow";
    if (options.format === "csv") {
        out = await view.to_csv();
    } else if (options.format === "columns") {
        out = JSON.stringify(await view.to_columns());
    } else if (options.format === "json") {
        out = JSON.stringify(await view.to_json());
    } else {
        out = await view.to_arrow();
    }
    if (options.format === "arrow") {
        if (options.output) {
            fs.writeFileSync(options.output, new Buffer(out), "binary");
        } else {
            console.log(new Buffer(out).toString());
        }
    } else {
        if (options.output) {
            fs.writeFileSync(options.output, out);
        } else {
            console.log(out);
        }
    }
    view.delete();
    tbl.delete();
}
21805
async function readStdin() {
  let code = "";
  const stdin = process.stdin;
  return new Promise(resolve => {
    stdin.setEncoding("utf8");
    stdin.on("readable", () => {
      const chunk = process.stdin.read();
      if (chunk !== null) code += chunk;
    });
    stdin.on("end", () => {
      resolve(code);
    });
  });
}
617525
function(data, encoding, callback) {
    if (this.error) {
      if (callback) {
        callback(error);
      }
      throw error;
    } else {
      return this.stream.write(data, encoding, callback);
    }
  }
446708
function stream (env) {
    let parseStream = parseFilter(env)

    let filter = through.obj((file, enc, cb) => cb(), function (cb) {
      parseStream.promise.then(data => {
        this.push(data)
        cb()
      }, cb)
    })

    return pipe(parseStream, filter)
  }
791565
function async(callback)
{
  var isAsync = false;

  // check if async happened
  defer(function() { isAsync = true; });

  return function async_callback(err, result)
  {
    if (isAsync)
    {
      callback(err, result);
    }
    else
    {
      defer(function nextTick_callback()
      {
        callback(err, result);
      });
    }
  };
}
1155944
function writeStream(filename, st) {
    var d = Q.defer();

    var wstream = fs.createWriteStream(filename);

    wstream.on('finish', function () {
        d.resolve();
    });
    wstream.on('error', function (err) {
        d.reject(err);
    });

    st.on('error', function(err) {
        d.reject(err);
    });

    st.pipe(wstream);

    return d.promise;
}