本文整理汇总了TypeScript中async.mapLimit函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mapLimit函数的具体用法?TypeScript mapLimit怎么用?TypeScript mapLimit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapLimit函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: callback
wicked.getAuthServerNames(function (err, authServerNames) {
if (err)
return callback(err);
async.mapLimit(authServerNames, MAX_PARALLEL_CALLS, function (authServerName, callback) {
wicked.getAuthServer(authServerName, callback);
}, function (err, authServers: WickedAuthServer[]) {
if (err)
return callback(err);
debug(JSON.stringify(authServers, null, 2));
// Fix auth server and API auth server IDs; also adapt
// the upstream_url (canonicalize it).
for (let i = 0; i < authServers.length; ++i) {
const as = authServers[i] as WickedAuthServer;
const id = `${authServerNames[i]}-auth`;
as.id = id;
if (as.config.api.hasOwnProperty('id'))
delete as.config.api.id;
as.config.api.name = id;
try {
const url = new URL(as.config.api.upstream_url);
as.config.api.upstream_url = url.toString();
} catch (err) {
const msg = `getAuthServerApis(): upstream_url for auth server ${authServerNames[i]} is not a valid URL: ${as.config.api.upstream_url}`;
return callback(new WickedError(msg, 500));
}
checkApiConfig(as.config);
}
callback(null, authServers);
});
});
示例2: mapLimit
const parseAndReportFiles = (fileGlobs: string[], program: ReporterProgramArgs): void => {
// Get all files and their resolved globs
const files = globby.sync(fileGlobs, {
cwd: process.cwd(),
ignore: program.ignore || [],
onlyFiles: true,
});
if (!files || !files.length) {
console.log(logSymbols.warning, 'No files found for reporting');
process.exit(1);
}
// Parallel read all of the given files
mapLimit(
files,
concurrencyLimit,
(file, cb) => readFile(resolve(process.cwd(), file), 'utf8', cb),
(err, results: string[]) => {
if (err) {
console.log(err);
process.exit(1);
}
const todos = results
.map(content => JSON.parse(content))
// filter files without any parsed content
.filter(item => item && item.length > 0)
.reduce((items, item) => items.concat(item), []);
outputTodos(todos, program);
}
);
};
示例3: function
deleteAppConsumers: function (appId, subscriptionList, callback) {
debug('deleteAppConsumers(): ' + appId);
async.mapLimit(subscriptionList, MAX_ASYNC_CALLS, function (subsInfo, callback) {
sync.deleteAppSubscriptionConsumer(subsInfo, callback);
}, function (err, results) {
if (err)
return callback(err);
debug('deleteAppConsumers() for app ' + appId + ' succeeded.');
callback(null);
});
},
示例4: function
getKongConsumers: function (portalConsumers: ConsumerInfo[], callback: Callback<ConsumerInfo[]>): void {
debug('getKongConsumers()');
async.mapLimit(
portalConsumers,
MAX_PARALLEL_CALLS,
(portalConsumer, callback) => getKongConsumerInfo(portalConsumer, callback),
function (err, results) {
if (err) {
error(err);
error(err.stack);
return callback(err);
}
debug('getKongConsumers() succeeded.');
return callback(null, results as ConsumerInfo[]);
});
},
示例5: has_auth
app.post(`${namespace}s`, has_body, has_auth(), //mk_valid_body_mw(user_schema),
function (req: restify.Request, res: restify.Response, next: restify.Next) {
type IResult = Array<[IContact, IPatient]>;
async.mapLimit(req.body.patients, 1, createPatient, (error, results: IResult) => {
if (error) return next(fmtError(error));
res.json(201, {patients: results});
return next();
});
/*
Patient.createEach(req.body.patients).exec((error, patients: Array<IPatient>) => {
if (error) return next(fmtError(error));
res.json(201, {'patients': patients});
return next();
});
*/
}
示例6: mapLimit
return new Promise<BlockDetailsByBlock>((resolve, reject) => {
if (blockNumbers.length === 0) return resolve([]);
console.log(`Fetching blocks details from ${blockNumbers[0]} to ${blockNumbers[blockNumbers.length - 1]}`);
let fetchedBlockCount = 0;
let highestBlockFetched = 0;
mapLimit(blockNumbers, BLOCK_DOWNLOAD_PARALLEL_LIMIT, (blockNumber, nextBlockNumber) => {
augur.rpc.eth.getBlockByNumber([blockNumber, false], (err: Error|null, block: BlockDetail): void => {
if (err) return nextBlockNumber(new Error("Could not get block"));
if (block == null) return nextBlockNumber(new Error(`Block ${blockNumber} returned null response. This is usually an issue with a partially sync'd parity warp node. See: https://github.com/paritytech/parity-ethereum/issues/7411`));
fetchedBlockCount++;
if (fetchedBlockCount % 10 === 0) console.log(`Fetched ${fetchedBlockCount} / ${blockNumbers.length} block details (current: ${highestBlockFetched})`);
if (blockNumber > highestBlockFetched) highestBlockFetched = blockNumber;
nextBlockNumber(undefined, [blockNumber, block]);
});
}, (err: Error|undefined, blockDetails: Array<[number, BlockDetail]>) => {
if (err) return reject(err);
const blockDetailsByBlock = _.fromPairs(blockDetails);
resolve(blockDetailsByBlock);
});
});
示例7: mapLimit
const parseAndReportFiles = (fileGlobs: string[], program: ProgramArgs): void => {
// Get all files and their resolved globs
const files = globby.sync(fileGlobs, {
cwd: process.cwd(),
ignore: program.ignore || [],
onlyFiles: true,
deep: true,
unique: true,
matchBase: true,
});
if (!files || !files.length) {
console.log(logSymbols.warning, 'No files found for parsing');
process.exit(1);
}
// Parallel read all of the given files
mapLimit(
files,
CONCURRENCY_LIMIT,
(file, cb) => readFile(resolve(process.cwd(), file), 'utf8', cb),
(err, results: string[]) => {
if (err) {
console.log(err);
process.exit(1);
}
const todos = results
.map(function(content: string, index: number) {
return parseContentSync(content, program, files[index]);
})
// filter files without any parsed content
.filter(item => item && item.length > 0)
.reduce((items, item) => items.concat(item), []);
outputTodos(todos, program);
}
);
};
示例8: parseInt
import * as async from "async";
var concurrencyCount = 0;
var fetchUrl = (url, callback) => {
var delay = parseInt(((Math.random() * 10000000) % 2000).toString(), 10);
concurrencyCount++;
console.log('现在的并发数是', concurrencyCount, ',正在抓取的是', url, ',耗时' + delay + '毫秒');
setTimeout(() => {
concurrencyCount--;
callback(null, url + 'html content');
}, delay);
}
var urls = [];
for (var i = 0; i < 30; i++) {
urls.push('http://datasource_' + i);
}
async.mapLimit(urls,5,(url,callback)=>{
fetchUrl(url,callback);
},(err,result)=>{
console.log('final:');
console.log(result);
})
示例9: enrichApplications
function enrichApplications(applicationList: WickedApplication[], apiPlans: WickedApiPlanCollection, apiList: ApiDescriptionCollection, callback: Callback<ConsumerInfo[]>) {
debug('enrichApplications(), applicationList = ' + utils.getText(applicationList));
async.mapLimit(applicationList, MAX_PARALLEL_CALLS, function (appInfo, callback) {
getApplicationData(appInfo.id, callback);
}, function (err, results) {
if (err)
return callback(err);
const consumerList = [];
for (let resultIndex = 0; resultIndex < results.length; ++resultIndex) {
const appInfo = results[resultIndex].application;
const appSubsInfo = results[resultIndex].subscriptions;
for (let subsIndex = 0; subsIndex < appSubsInfo.length; ++subsIndex) {
const appSubs = appSubsInfo[subsIndex];
// Only propagate approved subscriptions
if (!appSubs.approved)
continue;
let groupName = appSubs.api;
// Check if this API is part of a bundle
const apiDesc = apiList.apis.find(a => a.id === appSubs.api);
if (apiDesc) {
// API_BUNDLE: Use bundle as group name; this will mean that access tokens/API Keys for this API
// will also work for any other API which is part of this bundle.
if (apiDesc.bundle)
groupName = apiDesc.bundle;
} else {
warn(`enrichApplications: Could not find API configuration for API ${appSubs.api}`);
}
debug(utils.getText(appSubs));
const consumerInfo: ConsumerInfo = {
consumer: {
username: utils.makeUserName(appSubs.application, appSubs.api),
custom_id: appSubs.id
},
plugins: {
acls: [{
group: groupName
}]
}
};
if ("oauth2" == appSubs.auth) {
let redirectUris = appInfo.redirectUris;
if (!redirectUris || redirectUris.length == 0)
redirectUris = ['https://dummy.org'];
consumerInfo.plugins.oauth2 = [{
name: appSubs.application,
client_id: appSubs.clientId,
client_secret: appSubs.clientSecret,
redirect_uri: redirectUris
}];
} else if (!appSubs.auth || "key-auth" == appSubs.auth) {
consumerInfo.plugins["key-auth"] = [{
key: appSubs.apikey
}];
} else {
let err2 = new Error('Unknown auth strategy: ' + appSubs.auth + ', for application "' + appSubs.application + '", API "' + appSubs.api + '".');
return callback(err2);
}
// Now the API level plugins from the Plan
const apiPlan = getPlanById(apiPlans, appSubs.plan);
if (!apiPlan) {
const err = new Error('Unknown API plan strategy: ' + appSubs.plan + ', for application "' + appSubs.application + '", API "' + appSubs.api + '".');
return callback(err);
}
if (apiPlan.config && apiPlan.config.plugins) {
consumerInfo.apiPlugins = utils.clone(apiPlan.config.plugins);
}
else {
consumerInfo.apiPlugins = [];
}
// Fix #148: Apply Redis also for ratelimiting from Plans
checkCorsAndRateLimitingPlugins(apiDesc.name, consumerInfo.apiPlugins);
consumerList.push(consumerInfo);
}
}
debug(utils.getText(consumerList));
return callback(null, consumerList);
});
}