How to use the fibers/future.wait function in fibers

To help you get started, we’ve selected a few fibers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ThomasBurleson / angularjs-logDecorator / demos / webserver / node_modules / http-proxy / node_modules / utile / node_modules / rimraf / fiber.js View on Github external
if (rp.indexOf(opts.gently) !== 0) {
          var er = new Error("Refusing to delete: "+p+" not in "+opts.gently)
          er.errno = require("constants").EEXIST
          er.code = "EEXIST"
          er.path = p
          throw er
        }
      }

      if (!stat.isDirectory()) return fs2.unlink(p).wait()

      var rimrafs = fs2.readdir(p).wait().map(function (file) {
        return rimraf(path.join(p, file), opts)
      })

      Future.wait(rimrafs)
      fs2.rmdir(p).wait()
      timeout = 0
      return

    } catch (er) {
      if (er.message.match(/^EMFILE/) && timeout < EMFILE_MAX) {
        timer(timeout++).wait()
      } else if (er.message.match(/^EBUSY/)
                 && busyTries < opt.maxBusyTries) {
        timer(++busyTries * 100).wait()
      } else if (er.message.match(/^ENOENT/)) {
        // already gone
        return
      } else {
        throw er
      }
github isaacs / rimraf / fiber.js View on Github external
if (rp.indexOf(opts.gently) !== 0) {
          var er = new Error("Refusing to delete: "+p+" not in "+opts.gently)
          er.errno = require("constants").EEXIST
          er.code = "EEXIST"
          er.path = p
          throw er
        }
      }

      if (!stat.isDirectory()) return fs2.unlink(p).wait()

      var rimrafs = fs2.readdir(p).wait().map(function (file) {
        return rimraf(path.join(p, file), opts)
      })

      Future.wait(rimrafs)
      fs2.rmdir(p).wait()
      timeout = 0
      return

    } catch (er) {
      if (er.message.match(/^EMFILE/) && timeout < EMFILE_MAX) {
        timer(timeout++).wait()
      } else if (er.message.match(/^EBUSY/)
                 && busyTries < opt.maxBusyTries) {
        timer(++busyTries * 100).wait()
      } else if (er.message.match(/^ENOENT/)) {
        // already gone
        return
      } else {
        throw er
      }
github enyojs / ares-project / hermes / node_modules / rimraf / fiber.js View on Github external
if (rp.indexOf(opts.gently) !== 0) {
          var er = new Error("Refusing to delete: "+p+" not in "+opts.gently)
          er.errno = require("constants").EEXIST
          er.code = "EEXIST"
          er.path = p
          throw er
        }
      }

      if (!stat.isDirectory()) return fs2.unlink(p).wait()

      var rimrafs = fs2.readdir(p).wait().map(function (file) {
        return rimraf(path.join(p, file), opts)
      })

      Future.wait(rimrafs)
      fs2.rmdir(p).wait()
      timeout = 0
      return

    } catch (er) {
      if (er.message.match(/^EMFILE/) && timeout < EMFILE_MAX) {
        timer(timeout++).wait()
      } else if (er.message.match(/^EBUSY/)
                 && busyTries < opt.maxBusyTries) {
        timer(++busyTries * 100).wait()
      } else if (er.message.match(/^ENOENT/)) {
        // already gone
        return
      } else {
        throw er
      }
github pstadler / flightplan / lib / flight / remote.js View on Github external
exports.run = function(fn, context) {
  if(_connections.length === 0) {
    Future.wait(context.hosts.map(function(host) {
      var _context = extend({}, context);
      _context.remote = host;

      return connect(_context);
    }));
  }

  Future.wait(_connections.map(function(connection) {
    return execute(connection, fn);
  }));
};
github pstadler / flightplan / lib / transport / shell.js View on Github external
new Fiber(function() {
      results.push(self.exec(command, options));

      return future.return();
    }).run();

    return future;
  };

  var tasks = [];
  self._context.hosts.forEach(function(remote) {
    tasks.push(task(remote));
  });

  Future.wait(tasks);

  fs.unlinkSync(tmpFile);

  return results;
};
github pstadler / flightplan / lib / flight / local.js View on Github external
var task = function() {
    var transport = new Shell(_context);

    new Fiber(function() {
      fn(transport);
      return future.return();
    }).run();

    return future;
  };

  var t = process.hrtime();

  logger.info('Executing local task');

  Future.wait(task());

  logger.info('Local task finished after ' + prettyTime(process.hrtime(t)));
};
github pstadler / flightplan / lib / remote.js View on Github external
flight.status.executionTime = process.hrtime(t);
        this.status.executionTime = flight.status.executionTime;

        return future.return();
      }
    }.bind(this)).run();

    return future;
  }.bind(this);

  var tasks = [];
  for(var i=0, len=this.hosts.length; i < len; i++) {
    tasks.push(task(this.hosts[i]));
  }
  Future.wait(tasks);

  return this.status;
};