本文整理匯總了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));
});