在gulp任务中,我有以下代码创建一个gitAction promises数组,它在一个Promise.all()
语句中执行.之后,我正在进一步发表声明then()
.但是在then()
git拉入all()之前被调用已经终止.请问有什么线索吗?
var git = require('gulp-git'); var gitActionPromise = function(repo, url) { console.log('git action '+repo); var pathToRepo = './repos/'+repo; if (fs.lstatSync(pathToRepo).isDirectory()) { return new Promise((resolve, reject) => { git.pull('origin', 'master', {cwd: pathToRepo}, function (err) { console.log(repo + " pull done!"); if (err) { console.log('error'); reject(err); } else { console.log('ok'); resolve(); } }) }) } else { return new Promise((resolve, reject) => { git.clone(url, {cwd: pathToRepo}, function (err) { console.log(repo + " clone done!"); if (err) { console.log('error'); reject(err); } else { console.log('ok'); resolve(); } }) }) } }; var repos = package.repos || {}; var promises = Object.keys(repos).map(function(repo) { return gitActionPromise(repo, repos[repo]); }); Promise.all(promises).then( console.log('something else') <= this line was causing my issue ); needed to be enclosed in function
Joseph Silbe.. 9
你必须将一个函数传递给then
:
Promise.all(promises).then(function() { console.log('something else'); });
您只需立即记录"其他内容"即可.
你必须将一个函数传递给then
:
Promise.all(promises).then(function() { console.log('something else'); });
您只需立即记录"其他内容"即可.