处理promise中的返回值nodejs

我已经在NodeJs中构build了这个函数,

var Git = require('nodegit'); var fse = require('fs-extra'); var path = require('path'); var fs = require('fs'); var repoPath = 'D:\\sample' function gitCommitHistory(repoPath, callbackGitCommitHistory) { try { var open = Git.Repository.open; var commitList = []; open(repoPath) .then(function(repo) { return repo.getMasterCommit(); }) .then(function(firstCommitOnMaster) { var history = firstCommitOnMaster.history(); history.on("commit", function(commit) { if (commit === 'undefined') { callbackGitCommitHistory(null, commitList); } var author = commit.author(); commitList.push({commitAuthor:author.name(),commitAuthorEmail:author.email(), commitMessage:commit.message(), commitSha:commit.sha(), commitDate:commit.date()}); }); history.on("error", function(err){ console.log(err) }) history.on("end", function(){ callbackGitCommitHistory(null, commitList); }); history.start(); }); } catch (error) { callbackGitCommitHistory(error); } 

};

我已经使用模块“Nodegit”build立了这个function。 他们使用promises作为callback处理程序。

在这个函数中,我正在检索存储库中用户完成的所有提交,并将其作为对调用web服务的响应发送。

该函数工作正常,如果有至less一个提交,(即)repo.getMasterCommit返回提交历史logging。 但是,如果我给repoPath到一个新的回购零提交然后,没有什么是从该函数返回,因此我不能发送任何响应调用Web服务。 请帮助如何处理这种情况!!!!!!!!

GitHub回购相关的问题 。

这应该在下一个版本(0.5)中得到解决,目前通过661修复。 艾哈迈德·阿萨夫(Ahmad Assaf)是正确的,但是由于没有头脑提交,所以拒绝承诺链。