Esempio n. 1
0
require("jscex-async").init(); // 异步模块
require("jscex-async-powerpack").init(); // 异步增强模块

var cache = require('memory-cache'),
    _ = require('underscore');

var Binding = Jscex.Async.Binding,
    Task = Jscex.Async.Task;


Topic.findAsync = Binding.fromStandard(Topic.find);
Topic.findOneAsync = Binding.fromStandard(Topic.findOne);

var getListAsync = eval(Jscex.compile("async", function(topic_id, res){
  var topic = $await(Topic.findOneAsync({ _id: topic_id}));
  res.render('site/show', {
    topic: topic
  });
}));

exports.show = function(req, res, next){
  var topic_id = req.params.id;
  getListAsync(topic_id, res).start();
}

exports.digg = function(req, res, next){

  var topic_id = req.params.id,
      user_ip  = req.connection.remoteAddress;


  var ids = cache.get(user_ip);
Esempio n. 2
0
require("jscex-async-powerpack").init(Jscex);
var Jscexify = Jscex.Async.Jscexify;
var data = require('./data');

// 将异步获取数据函数封装成Jscex异步函数
for (var i in data) {
  if (i.substr(0, 7) !== 'getData')
    continue;
  data[i + 'Async'] = Jscexify.fromStandard(data[i]);
}

eval(Jscex.compile('async', function () {
  var data1, data2, data3, data4, data5;
  try {
    data1 = $await(data.getData1Async());
    data2 = $await(data.getData2Async());
    data3 = $await(data.getData3Async()); 
    data4 = $await(data.getData4Async());
    data5 = $await(data.getData5Async());
    console.log(data.render({
      data1:  data1,
      data2:  data2,
      data3:  data3,
      data4:  data4,
      data5:  data5
    }));
  }
  catch (err) {
    console.log(err.stack);
  }
}))().start();