本文整理汇总了TypeScript中async.each函数的典型用法代码示例。如果您正苦于以下问题:TypeScript each函数的具体用法?TypeScript each怎么用?TypeScript each使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了each函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
Collections.Tips.find({unregisteredUser: true, accepted: false, refunded: false}).toArray(function(err: Error, unregisteredUserTips: any[]) {
async.each(unregisteredUserTips, function(tip, callback) {
var tipTime = tip["_id"].getTimestamp().valueOf();
var currentTime = Date.now();
if ((currentTime - tipTime) > (60 * 60 * purgeTime * 1000)) { // x hours in milliseconds
// Remove friend
bot.removeFriend(tip.recipient.id);
// Tip is older than 6 hours and has not been accepted
var tipComment = {
"sender": tip.recipient.name,
"recipient": tip.sender.name,
"refund": true,
"USD": tip.amount * prices["GMC/USD"]
};
gamerscoin.move(tip.recipient.id, tip.sender.id, tip.amount, 1, stringifyAndEscape(tipComment), function(err: any, success: boolean) {
if (err) {
callback(err);
return;
}
Collections.Tips.update({"_id": tip["_id"]}, {$set: {"refunded": true}}, {w:1}, callback);
});
}
else {
callback(null);
}
}, function(err) {
if (err) {
console.error("An error occurred: " + reportError(err, "Checking for expired tips to refund", true));
}
});
});
示例2: function
fs.readdir(dir, function (err, files) {
var returnFiles = [];
async.each(files, function (file, next) {
var filePath = path.join(dir,file);
fs.stat(filePath, function (err, stat) {
if (err) {
return next(err);
}
if (stat.isDirectory()) {
scan(filePath, suffix, function (err, results) {
if (err) {
return next(err);
}
returnFiles = returnFiles.concat(results);
next();
})
}
else if (stat.isFile()) {
if (file.indexOf(suffix, file.length - suffix.length) !== -1) {
returnFiles.push(filePath);
}
next();
}
});
}, function (err) {
callback(err, returnFiles);
});
});
示例3: getLatestRelease
getLatestRelease("https://github.com/superpowers/superpowers-core", (version, downloadURL) => {
const packageData = fs.readFileSync(`${__dirname}/../../package.json`, { encoding: "utf8" });
const { version: localVersion } = JSON.parse(packageData);
let isLocalDev = true;
try { if (!fs.lstatSync(`${__dirname}/../../.git`).isDirectory()) isLocalDev = false; }
catch (err) { isLocalDev = false; }
registry.core = { version, downloadURL, localVersion, isLocalDev };
async.each(Object.keys(registry.systems), (systemId, cb) => {
const system = registry.systems[systemId];
getLatestRelease(system.repository, (version, downloadURL) => {
system.version = version;
system.downloadURL = downloadURL;
if (systemsById[systemId] != null) {
system.localVersion = systemsById[systemId].version;
system.isLocalDev = systemsById[systemId].isDev;
} else {
system.isLocalDev = false;
}
cb();
});
}, (err) => { callback(err, registry); });
});
示例4: cb
SupCore.system.serverBuild = (server: ProjectServer, buildPath: string, callback: (err: string) => void) => {
fs.mkdirSync(`${buildPath}/files`);
const assetIdsToExport: string[] = [];
server.data.entries.walk((entry: SupCore.Data.EntryNode, parent: SupCore.Data.EntryNode) => {
if (entry.type != null && server.system.data.assetClasses[entry.type].prototype.serverExport != null) assetIdsToExport.push(entry.id);
});
let files: string[] = [];
async.each(assetIdsToExport, (assetId, cb) => {
server.data.assets.acquire(assetId, null, (err: Error, asset: ServerExportableAsset) => {
asset.serverExport(`${buildPath}/files`, (err, writtenFiles) => {
server.data.assets.release(assetId, null);
files = files.concat(writtenFiles);
cb();
});
});
}, (err) => {
if (err != null) { callback("Could not export all assets"); return; }
const json = JSON.stringify(files, null, 2);
fs.writeFile(`${buildPath}/files.json`, json, { encoding: "utf8" }, (err) => {
if (err != null) { callback("Could not save files.json"); return; }
callback(null);
});
});
};
示例5: Paper
async.map(referenceParagraphs, resolveReferenceParagraph, (error, resolvedPapers: PaperRow[]) => {
if (error) return callback(error);
resolvedPapers.forEach((resolvedPaper, i) => {
var matchString = resolvedPaper ? new Paper(resolvedPaper).toReference() : 'N/A';
var matchDistance = resolvedPaper ? resolvedPaper['distance'] : '';
logger.debug(` "${chalk.yellow(referenceParagraphs[i])}" -> ${chalk.green(matchString)} ${chalk.magenta(matchDistance)}`);
});
// filter out the null resolved papers (no match)
var citedPapers = resolvedPapers.filter(paper => !!paper);
// insert all the resolved matches as citations
async.each(citedPapers, (citedPaper: PaperRow, callback: ErrorCallback) => {
db.Insert('citation')
.set({
citing_paper_id: article.id,
cited_paper_id: citedPaper.id,
})
.execute(error => {
// ignore unique constraint violations
if (error && error.code === '23505') {
return callback(null);
}
return callback(error);
});
}, (error) => {
if (error) return callback(error);
callback(null, {citing_paper_id: article.id, cited_papers_ids: citedPapers.map(paper => paper.id)});
});
});
示例6: function
.then (function (Documents) {
// Ensure that the files have been recreated from the GridFS data
async.each (Documents, retrieveFileFromDbWithCallback, function (err) {
err ? reject (err) : resolve (Documents);
});
})
示例7: load
export function load(contextNames: string[], callback: () => void) {
async.each(contextNames, loadContext.bind(null, languageCode, contexts), () => {
if (languageCode === "en") { callback(); return; }
async.each(contextNames, loadContext.bind(null, "en", fallbackContexts), callback);
});
}
示例8: before
before(function(done) {
TABLES[1].table = dataset.table(generateName('table'));
TABLES[2].table = dataset.table(generateName('table'));
async.each(
TABLES,
function(tableObject, next) {
const tableInstance = tableObject.table;
tableInstance.create(
{
schema: SCHEMA,
},
next
);
},
function(err) {
if (err) {
done(err);
return;
}
const table1Instance = TABLES[1].table;
table1Instance.insert(TABLES[1].data, done);
}
);
});
示例9: setup
export function setup(toolPaths: { [name: string]: string; }, callback: Function) {
toolsByName = {};
const pluginsRoot = `/systems/${SupCore.system.id}/plugins`;
async.each(Object.keys(toolPaths), (toolName, cb) => {
const toolTitle = SupClient.i18n.t(`${toolPaths[toolName]}:editors.${toolName}.title`);
const pluginPath = toolPaths[toolName];
toolsByName[toolName] = { title: toolTitle, pluginPath, pinned: false };
SupClient.fetch(`${pluginsRoot}/${pluginPath}/editors/${toolName}/manifest.json`, "json", (err: Error, toolManifest: ToolManifest) => {
if (err != null) { cb(err); return; }
toolsByName[toolName].pinned = toolManifest.pinned;
cb();
});
}, (err) => {
if (err != null) { callback(err); return; }
toolsElt.innerHTML = "";
const toolNames = Object.keys(toolsByName);
toolNames.sort((a, b) => toolsByName[a].title.localeCompare(toolsByName[b].title));
for (const toolName of toolNames) setupTool(toolName);
callback();
});
}
示例10: join
// handle copying or linking necessary assets
cb => async.each(packs, (pack, next2) => {
const dir = join(assetsDir, pack.id);
if (pack.mode === 'images') {
linkDirs(resolve(pack.path, pack.images.directory), dir, next2);
} else if (pack.mode === 'sprite') {
const filename = basename(pack.sprite.file);
async.series([
cb2 => mkdirp(dir, cb2),
cb2 => copy(resolve(pack.path, pack.sprite.file), join(dir, filename), cb2),
], next2);
} else { // pack.mode === 'font'
const fontFiles = [
pack.font.eot,
pack.font.svg,
pack.font.woff,
pack.font.ttf,
pack.font.woff2,
].filter(Boolean);
async.series([
cb2 => mkdirp(dir, cb2),
cb2 => async.each(fontFiles, (file, next3) => {
const filename = basename(file);
copy(resolve(pack.path, file), join(dir, filename), next3);
}, cb2),
], next2);
}
}, cb),