#!/usr/bin/env node

// A trivial program that writes “yes” one million times, based on the Node
// “drain” event example [1].
//
// [1] http://nodejs.org/api/stream.html#stream_event_drain)

var rw = require("../");

var writer = rw.fileWriter("/dev/stdout"),
    data = new Buffer("yes\n"),
    i = 1e6;

(function flow(error) {
  if (error) throw error;

  while (--i >= 0) {
    if (!writer.write(data)) {
      return writer.drain(flow);
    }
  }

  writer.end();
})();
