本文整理汇总了TypeScript中@ts-task/task.Task.all方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Task.all方法的具体用法?TypeScript Task.all怎么用?TypeScript Task.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ts-task/task.Task
的用法示例。
在下文中一共展示了Task.all方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: generate
generate (helpers: unknown) {
const self = this;
const tasks: Task<unknown, NodeJS.ErrnoException | UnknownError>[] = [];
if (self.generatorSettings.copyAssets) {
tasks.push(self.copyAssets());
}
// TODO: Remove the files settings, probably walk the dir for .tpl files
for (let i = 0; i < self.generatorSettings.files.length; i++) {
// Create the object in charge of rendering the html
const renderObject = new HtmlWriterFile({
inputFile: self.generatorSettings.files[i] + '.tpl',
outputFile: self.generatorSettings.outputDir + '/' + self.generatorSettings.files[i] + '.html',
renderer: self.renderer
});
// ...
renderObject.setHelpers(helpers);
// Generate the html
tasks.push(renderObject.render());
}
return Task.all(tasks);
}
示例2: generate
generate () {
const self = this;
const tasks: ReturnType<typeof writeFileCreateDir>[] = [];
self.metadata.renderedFragments = {};
// For each markdown, create the html fragment
for (const mdTemplate in self.metadata.jsonml) {
try {
const tree = markdown.toHTMLTree(self.metadata.jsonml[mdTemplate]);
const html = markdown.renderJsonML(tree);
const outputFilename = self.generatorSettings.outputDir + '/' + mdTemplate + '.html';
// mhmhmh TODO: This is sooo hardcoded
self.metadata.renderedFragments[mdTemplate] = 'fragment/' + mdTemplate + '.html';
tasks.push(writeFileCreateDir(outputFilename, html));
} catch (e) {
// TODO: Catch this better
console.log(red('Problem with ') + mdTemplate);
throw e;
}
}
return Task.all(tasks);
}
示例3:
export function traverseDictionary<T, E> (objOfTasks: Dictionary<Task<T, E>>): Task<Dictionary<T>, UnknownError | E> {
// Create an array of task with a tuple containing the key and the value
const tasks =
Object.keys(objOfTasks)
.map(key => objOfTasks[key]
.map(value => ({key, value}))
);
// Wait until all tasks are resolved
return Task.all(tasks)
// And transform the array back into an object
.map(pairs => {
const ans: Dictionary<T> = {};
pairs.forEach(({key, value}) => ans[key] = value);
return ans;
});
}
示例4:
.chain(function (files) {
const promises: ReturnType<typeof copyFile>[] = [];
for (let i = 0; i < files.length; i++) {
const m = files[i].match(matchRe);
if (m) {
const inputFilename = files[i];
const outputFilename = dst + '/' + files[i].substr(dirNameLength + 1);
// console.log(inputFilename.grey + " => ".green + outputFilename.grey);
// Copy the file
promises.push(copyFile(inputFilename, outputFilename));
}
}
return Task.all(promises);
});
示例5: readdir
return readdir(dir).chain(files => {
// An array of tasks of the file stat (to see if we need to recurse or not)
const filePromises: Array<Task<string[], NodeJS.ErrnoException | UnknownError>> = [];
// For each file, check if directory. If it is, recurse, if not
// boom.
for (let i = 0; i < files.length; i++) {
const filename = dir + '/' + files[i];
// Do not include excluded files
if (isFileExcluded(filename, options)) {
continue;
}
// Check if it is a directory or not
filePromises.push(
stat(filename)
.chain(checkIsDirectory(filename, options))
);
}
return Task.all(filePromises).map(x => _.flatten(x));
});