Answer the question
In order to leave comments, you need to log in
How to do asynchronous execution in gulp?
Good afternoon! It is necessary to start and wait for the task to be completed with bootprint, but it does not work with pipe how to do this, tell me?
I have such a task:
function generateDocsHtml() {
return function (cb) {
let bootprintService =
bootprint
.load(bootprint_swagger)
.merge({
handlebars : {
partials : path.join(__dirname, partials),
templates : path.join(__dirname, templates),
helpers : path.join(__dirname, helpers),
data : {
items : items
}
},
less : {
main : [
path.join(__dirname, less + '/theme.less'),
path.join(__dirname, less + '/vars.less')
]
}
});
return glob(build + '/**/*.json', function (err, files) {
const items = [];
for (let pathFile of files) {
let fileName = pathFile.substring(pathFile.lastIndexOf('/') + 1);
const savePath = path.join(__dirname, build);
let name = fileName.split('.')[0].toLowerCase();
items.push({
name : name,
fileName : fileName,
});
}
items.forEach((item) => {
const savePath = path.join(__dirname, build);
bootprintService
.build(path.join(__dirname, build + '/' + item.name + '/' + item.name + '.json'), savePath + '/' + item.name)
.generate()
.done();
});
});
}
}
Answer the question
In order to leave comments, you need to log in
What else is return glob() ?
Everything is very simple - in done, call the task completion callback
Something like this
bootprintService
…
.done(function(){ cb() });
let services = [];
items.forEach((item) => {
services.push(new Promise((resolve, reject)=>{
bootprintService
...
.done(() => resolve());
}))
});
Promise.all(services)
.then(function(){ cb() })
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question