How to use eventproxy - 10 common examples

To help you get started, we’ve selected a few eventproxy 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 dead-horse / callback_hell / count_lines / eventproxy.js View on Github external
function count(dirname) {
  var ep = Eventproxy.create();
  ep.fail(function (err) {
    console.error(err.stack);
  });

  fs.readdir(dirname, ep.doneLater('files'));

  ep.once('files', function (files) {
    files.forEach(function (filename) {
      var filepath = path.join(dirname, filename);
      fs.stat(filepath, ep.doneLater(function (stat) {
        ep.emit('stat', {
          stat: stat,
          filepath: filepath,
          filename: filename
        });
      }));
github expressjs / connect-markdown / lib / connect-markdown.js View on Github external
var getContent = function getContent(filepath, callback) {
    var ep = eventproxy.create();
    ep.fail(callback);

    fs.readFile(filepath, 'utf8', ep.doneLater(function (content) {
      var title = content.slice(0, content.indexOf('\n')).trim().replace(/^[#\s]+/, '');
      var body = marked(content);
      ep.emit('data', {title: title, body: body});
    }));
    fs.readFile(options.layout, 'utf8', ep.done('layout'));

    ep.all('layout', 'data', function (layout, data) {
      var html = layout.replace(options.titleHolder, data.title)
       .replace(options.bodyHolder, data.body);
      callback(null, html);
    });
  };
github node-modules / weibo / lib / tbase.js View on Github external
TBase.prototype.count = function (user, ids, callback) {
  if (typeof ids === 'string') {
    ids = ids.split(',');
  }
  var list = [];
  while (ids.length > this.config.count_max_number) {
    list.push(ids.splice(0, this.config.count_max_number));
  }
  if (ids.length > 0) {
    list.push(ids);
  }
  var ep = EventProxy.create();
  ep.after('counts', list.length, function (results) {
    var counts = [];
    for (var i = 0; i < results.length; i++) {
      counts = counts.concat(results[i]);
    }
    callback(null, counts);
  });
  ep.once('error', function (err) {
    ep.unbind();
    callback(err);
  });
  var self = this;
  list.forEach(function (ids) {
    self._count.call(self, user, ids.join(','), function (err, counts) {
      if (err) {
        return ep.emit('error', err);
github yanghua / FixedAssetManagerServer / proxy / fixedAsset.js View on Github external
exports.getUserIdByUserName= function(userName, callback) {
    var ep = EventProxy.create();
    userName = '%'+userName+'%';
    var paramObj = {
        userName: userName,
    };
    mysqlClient.query({
        sql: "SELECT userId,department,userName FROM USER WHERE userName like :userName ;",
        params: paramObj
    }, function(err, rows) {
        if (err || !rows) {
            console.dir(err);
            return callback(new ServerError(), null);
        }
        callback(null, rows);
    });
};
github yanghua / FixedAssetManagerServer / controllers / inventory.js View on Github external
exports.exportInv = function(req, res, next) {
    debugCtrller("/controllers/stockIn/exportInv");

    if (!req.session || !req.session.user) {
        return res.redirect("/login");
    }
    var ep = EventProxy.create();

    //静态标题
    var conf = {};
    conf.cols = [{
        caption: '名称',
        type: 'string'
    }, {
        caption: '类别',
        type: 'string'
    }, {
        caption: '单位',
        type: 'string'
    }, {
        caption: '单价',
        type: 'string'
    }, {
github yanghua / FixedAssetManagerServer / controllers / stockOut.js View on Github external
exports.exportSO = function(req, res, next) {
    debugCtrller("controllers/fixedAsset/exportExcel");
    if (!req.session || !req.session.user) {
        return res.redirect("/login");
    }
    var ep = EventProxy.create();

    //静态标题
    var conf = {};
    conf.cols = [{
        caption: '出库日期',
        type: 'string'
    }, {
        caption: '申请人',
        type: 'string'
    }, {
        caption: '类别',
        type: 'string'
    }, {
        caption: '商品名称',
        type: 'string'
    }, {
github yanghua / FixedAssetManagerServer / controllers / stockIn.js View on Github external
exports.exportSI = function(req, res, next) {
    debugCtrller("/controllers/stockIn/exportSI");

    if (!req.session || !req.session.user) {
        return res.redirect("/login");
    }
    var ep = EventProxy.create();

    //静态标题
    var conf = {};
    conf.cols = [{
        caption: '入库日期',
        type: 'string'
    }, {
        caption: '类别',
        type: 'string'
    }, {
        caption: '商品名称',
        type: 'string'
    }, {
        caption: '单位',
        type: 'string'
    }, {
github yanghua / FixedAssetManagerServer / controllers / fixedAsset.js View on Github external
exports.exportExcel = function (req, res, next) {
    debugCtrller("controllers/fixedAsset/exportExcel");
    var companyId    = req.params.companyId || "";

    try {
        check(companyId).notEmpty();
    } catch (e) {
        return res.send(resUtil.generateRes(null, config.statusCode.STATUS_INVAILD_PARAMS));
    }
    var ep = EventProxy.create();

    //静态标题
    var conf ={};
    conf.cols = [
        {caption:'部门', type:'string'},
        {caption:'部门编号', type:'string'},
        {caption:'领用人', type:'string'},
        {caption:'领用人工号', type:'string'},
        {caption:'设备编号', type:'string'},
        {caption:'旧编号', type:'string'},
        {caption:'资产名称', type:'string'},
        {caption:'资产类型', type:'string'},
        {caption:'资产归属', type:'string'},
        {caption:'当前状态', type:'string'},
        {caption:'品牌', type:'string'},
        {caption:'型号', type:'string'},
github cnodejs / nodeclub / controllers / user.js View on Github external
exports.refreshToken = function (req, res, next) {
  var user_id = req.session.user._id;

  var ep = EventProxy.create();
  ep.fail(next);

   User.getUserById(user_id, ep.done(function (user) {
    user.accessToken = uuid.v4();
    user.save(ep.done(function () {
      res.json({status: 'success', accessToken: user.accessToken});
    }));
  }));
};
github dead-horse / callback_hell / parallel / eventproxy.js View on Github external
function get(callback) {
  var ep = Eventproxy.create();
  ep.fail(callback);

  proxy.getUser(ep.done('user'));
  ep.once('user', function (user) {
    proxy.getPosts(user, ep.done('posts'));
    proxy.getComments(user, ep.done('comments'));
  });

  ep.all('user', 'posts', 'comments',
    function (user, posts, comments) {
    callback(null, {
      user: user,
      posts: posts,
      comments: comments
    });
  });

eventproxy

An implementation of task/event based asynchronous pattern.

MIT
Latest version published 7 years ago

Package Health Score

53 / 100
Full package analysis

Popular eventproxy functions