【问题标题】:Why there is a part of the code who is not executed? Node.js/Oriento为什么有一部分代码没有执行? Node.js/Oriento
【发布时间】:2016-10-12 23:40:09
【问题描述】:

我已经调用了一个函数 function select(items ,className, callback) ,它在 console.log 内部有 console.log("Function ran.") 并且 console.log 从来没有生成过。

这里我叫它:

io.on('connection', function(socket){
  console.log('User connected.');

  openServer();  //This start the connection between OrientDB and the Server

  select("name", "Buyers", function(err, data){
    if(err){
      console.log("ERROR: ", err);
    } else {
      console.log("result from db is: ", data);
    }
  });

函数代码:

function select(items ,className, callback){

    server.query("SELECT "+items+" FROM "+className+"", function(err, result){
      console.log("Function ran.");
      if (err) 
        return callback(err, null);
      else
        return callback(null, result[0].name);
    });
  }

console.log()select function() 均未执行。

我的问题是:

  • 为什么他们永远不会被处决?

【问题讨论】:

  • 在触发io.on('connection' 回调函数之前不会调用select - 所以唯一的问题是,你永远不会发生连接
  • “openServer”中的代码是异步的吗?
  • 当您说“console.log() 均未执行”时,您的意思是您发布的代码中的四个都没有?
  • 我指的是function select上的console.log
  • 所以输出'User connected.'

标签: javascript node.js orientdb oriento


【解决方案1】:

OrientJS 作为旧的 Oriento 使用 Promises

http://orientdb.com/docs/last/OrientJS-Query.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多