本文整理汇总了TypeScript中async.queue函数的典型用法代码示例。如果您正苦于以下问题:TypeScript queue函数的具体用法?TypeScript queue怎么用?TypeScript queue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了queue函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: startToReceiveRestoreMessages
private startToReceiveRestoreMessages(restoreTopic: Topic,
drainEvent: Function): any {
const asyncQueue = async.queue((msg, done) => {
setImmediate(() => drainEvent(msg, err => {
if (err) {
done(err);
} else {
done();
}
}));
}, 1);
asyncQueue.drain = () => {
// commit state first, before resuming
this.logger.verbose('Committing offsets upon async queue drain');
new Promise((resolve, reject) => {
restoreTopic.consumer.commit((err, data) => {
if (err) {
return reject(err);
}
resolve(data);
});
}).then(() => {
this.logger.info('Offset committed successfully');
}).catch((err) => { });
};
this.logger.info('Async queue draining started.');
return asyncQueue;
}
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:29,代码来源:index.ts
示例2: find
find(usermap, final_callback) {
if (!gapis.datastore)
return setTimeout(this.find.bind(this), 300, usermap, final_callback);
let users = {}
var q = async.queue((user_id, queue_callback) => {
if (!user_id || !_.isString(user_id.route))
return queue_callback('Invalid user');
async.waterfall([
(callback) => {
this.ofType(user_id.route).findById(user_id.id, callback);
}, (user, callback) => {
let authorized = this.ofType(user_id.route).isAuthorized(user);
callback(null, authorized ? user : null);
}], queue_callback);
});
q.drain = () => {
final_callback(null, Object.keys(users).length ? users : null);
}
_.forEach(usermap, (user_id) => {
q.push(user_id, (err, user) => {
if (err)
logging.error(err);
else if (user)
users[user.route] = user;
});
});
}
开发者ID:zaksie,项目名称:gotouch,代码行数:30,代码来源:user-router.ts
示例3: downloadAugurLogs
export function downloadAugurLogs(db: Knex, augur: Augur, fromBlock: number, toBlock: number, blocksPerChunk: number|undefined, callback: ErrorCallback): void {
const batchLogProcessQueue = queue((processFunction: (callback: ErrorCallback) => void, nextFunction: ErrorCallback): void => {
processFunction(nextFunction);
}, 1);
logger.info(`Getting Augur logs from block ${fromBlock} to block ${toBlock}`);
let lastBlockDetails = new Promise<BlockDetailsByBlock>((resolve) => resolve([]));
augur.events.getAllAugurLogs({ fromBlock, toBlock, blocksPerChunk }, (batchOfAugurLogs: Array<FormattedEventLog>, blockRange: BlockRange): void => {
if (!batchOfAugurLogs || batchLogProcessQueue.paused) return;
const blockNumbers = batchOfAugurLogs.length > 0 ? extractBlockNumbers(batchOfAugurLogs) : getBlockNumbersInRange(blockRange);
const blockDetailPromise = lastBlockDetails.then(() => fetchAllBlockDetails(augur, blockNumbers));
lastBlockDetails = blockDetailPromise;
batchLogProcessQueue.push(async (nextBatch) => {
try {
await processBatchOfLogs(db, augur, batchOfAugurLogs, blockNumbers, blockDetailPromise);
nextBatch(null);
} catch (err) {
batchLogProcessQueue.kill();
batchLogProcessQueue.pause();
callback(err);
}
});
},
(err) => {
if (!batchLogProcessQueue.paused) {
batchLogProcessQueue.push(() => {
callback(err);
batchLogProcessQueue.kill();
});
}
});
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:32,代码来源:download-augur-logs.ts
示例4: connect
connect():Promise<string> {
this.serialPort = new SerialPort(this.port, this.serialPortOptions);
this.serialPort.on("open", (err: any) => (this.onOpen()));
this.serialPort.on("data", (data : Buffer) => (this.onReceive(data)));
this.serialPort.on("error", (error:any) => (this.onError(error)));
this.serialPort.on("disconnect", (error:any) => (this.onDisconnect(error)));
this.serialPort.on("close", (error: any) => (this.onClose()));
this.timer = setInterval(() => this.timerPoll(), 200);
var __this = this;
this.requestQueue = async.queue(function(task : Task, callback : Function) {
task.callback = callback;
__this.execute(task);
}, 1);
//PATCH: async/queue
//mercyKill takes callback for each task cleanup
//https://github.com/caolan/async/issues/1262
//Need to modify internal queue/kill method, rename this function to kill
this.requestQueue.mercyKill = function(callback : Function) {
if (!callback)
return this.kill();
while ( this._tasks.length > 0){
var node = this._tasks.shift();
callback(node.data);
}
}
//FIXME: this is not working against new promise closure
//var _this = this;
return new Promise(function(resolve : Function, reject : Function){
__this.serialPort.on("open", function() {
resolve();
});
__this.serialPort.on("error", function(err :any) {
reject(err);
});
__this.serialPort.open();
});
}
开发者ID:nodesense,项目名称:nodesense-modbus-serial,代码行数:53,代码来源:modbus-serial.ts
示例5: fetchFor
fetchFor(placeids, yield_callback, final_callback) {
var q = async.queue((placeid, callback) => {
this.fetchForAux(placeid, yield_callback, callback);
});
q.drain = () => {
final_callback();
}
placeids.forEach((placeid) => {
q.push(placeid, function (err, tab) {
if (err)
return logging.error(err)
});
});
}
开发者ID:zaksie,项目名称:gotouch,代码行数:16,代码来源:order-approved.ts
示例6: queue
queue(iteratees, func, yield_callback, final_callback) {
var q = async.queue(func.bind(this));
q.drain = () => {
if (final_callback)
final_callback();
}
iteratees.forEach((iteratee) => {
q.push(iteratee, (err, result) => {
if (err)
logging.error(err);
if (yield_callback)
yield_callback(err, result);
});
});
}
开发者ID:zaksie,项目名称:gotouch,代码行数:17,代码来源:endpoint.ts
示例7: fetchMultipleArticles
fetchMultipleArticles(placeid, pids, final_callback) {
pids = _.uniq(pids);
var results = {};
var errors = [];
var q = async.queue((pid, callback) => {
this.fetchArticle(placeid, pid, callback);
});
q.drain = () => {
let err = errors.length < 1 ? null : errors;
final_callback(err, results);
}
pids.forEach((pid) => {
q.push(pid, (err, result) => {
if (err)
errors.push(err);
else {
results[pid] = result;
}
});
});
}
开发者ID:zaksie,项目名称:gotouch,代码行数:23,代码来源:article.ts
示例8: beforeEach
beforeEach(() => q = async.queue((task: Task, callback) => {
setTimeout(() => {
t.push(task.res);
callback();
}, task.time);
}, 4));
开发者ID:Dev-I-Ant,项目名称:node-misc,代码行数:6,代码来源:asyncQueue.spec.ts
示例9: function
;(async function (){
const answers = await inquirer.prompt<{ password: string, username: string }>([
{
default: 'msdacia',
message: 'User Name:',
name: 'username',
type: 'input'
},
{
message: 'Password:',
name: 'password',
type: 'password'
}
])
const { username, password } = answers
const sftp = new SftpClient()
const createQueue = async.queue<CreatePayload, Error>(({ observer, remotePath, title }, callback) => {
createQueue.drain = () => observer.complete()
observer.next(title)
sftp.mkdir(remotePath, true).then(() => callback()).catch(callback)
})
const uploadQueue = async.priorityQueue<UploadPayload, Error>(({ localPath, observer, remotePath, title }, callback) => {
uploadQueue.drain = () => observer.complete()
const remainingCount = uploadQueue.length()
const inProgressTitles = uploadQueue.workersList()
.map(worker => worker.data.title)
.sort()
.map(title => title.length <= 27 ? title : `${title.substr(0, 12)}...${title.slice(-12)}`)
const message = inProgressTitles.join(', ') + (remainingCount ? ` + ${remainingCount} more` : '')
observer.next(message)
sftp.put(localPath, remotePath, true).then(() => callback()).catch(callback)
}, 4)
const deleteQueue = async.queue<DeletePayload, Error>(({ observer, remotePath, title }, callback) => {
deleteQueue.drain = () => observer.complete()
observer.next(title)
sftp.delete(remotePath).then(() => callback()).catch(callback)
})
try {
await sftp.connect({ host: HOST, username, password })
const [localFiles, remoteFiles] = await Promise.all([
(await readdir('dist')).map(file => path.relative('dist', file)).map(file => path.posix.format(path.parse(file))),
(await readdirRemote(sftp, DEPLOY_DIR)).map(file => path.posix.relative(DEPLOY_DIR, file)),
])
const remoteFilesToDelete = getRemoteFilesToDelete(remoteFiles, localFiles)
const remoteDirectoriesToCreate = getRequiredDirectories(localFiles)
const createObserver = new Observable<string>(observer => {
for (const directory of remoteDirectoriesToCreate) {
const remotePath = path.posix.join(DEPLOY_DIR, directory)
createQueue.push({ observer, remotePath, title: directory })
}
})
const uploadObserver = new Observable<string>(observer => {
for (const file of localFiles) {
const localPath = path.resolve(path.join('dist', file))
const remotePath = path.posix.join(DEPLOY_DIR, file)
const payload: UploadPayload = {
localPath,
observer,
remotePath,
title: file,
}
uploadQueue.push(payload, getUploadPriority(file))
}
})
const deleteObserver = new Observable<string>(observer => {
for (const file of remoteFilesToDelete) {
const remotePath = path.posix.join(DEPLOY_DIR, file)
deleteQueue.push({ observer, remotePath, title: file })
}
})
await new Listr([
{
title: `Creating ${remoteDirectoriesToCreate.length} Directories`,
task: () => createObserver as any,
skip: () => remoteDirectoriesToCreate.length === 0 ? 'No directories to create' : '',
},
{
title: `Uploading ${localFiles.length} File(s)`,
task: () => uploadObserver as any,
skip: () => localFiles.length === 0 ? 'No files to upload' : '',
},
{
title: `Deleting ${remoteFilesToDelete.length} File(s)`,
task: () => deleteObserver as any,
skip: () => remoteFilesToDelete.length === 0 ? 'No files to delete' : '',
},
]).run()
//.........这里部分代码省略.........
开发者ID:MsDacia,项目名称:msdacia,代码行数:101,代码来源:deploy.ts
示例10: downloadImageUrls
downloadImageUrls(imageKeys?: string[], imageProviders?: string[]) {
if (!this.appSettings.offlineMode) {
let allImagesRetrieved = true;
let imageQueue = queue((task, callback) => callback());
if (imageKeys === undefined || imageKeys.length === 0) {
imageKeys = Object.keys(this.appImages);
}
for (let i = 0; i < imageKeys.length; i++) {
let image = this.appImages[imageKeys[i]];
let imageProvidersForKey: string[] = imageProviders === undefined || imageProviders.length === 0 ? image.defaultImageProviders : imageProviders;
imageProvidersForKey = _.intersection(this.appSettings.enabledProviders, imageProvidersForKey);
if (image !== undefined && !image.retrieving) {
let numberOfQueriesForImageKey = image.searchQueries.length * imageProvidersForKey.length;
if (numberOfQueriesForImageKey > 0) {
image.retrieving = true;
allImagesRetrieved = false;
this.previewVariables.numberOfQueriedImages += numberOfQueriesForImageKey;
for (let j = 0; j < image.searchQueries.length; j++) {
this.imageProviderService.instance.retrieveUrls(image.searchQueries[j], imageProvidersForKey, <K extends keyof ProviderCallbackEventMap>(event: K, data: ProviderCallbackEventMap[K]) => {
switch (event) {
case 'error':
{
let errorData = (data as ProviderCallbackEventMap['error']);
if (typeof errorData.error === 'number') {
this.loggerService.error(this.lang.errors.providerError__i.interpolate({
provider: errorData.provider,
code: errorData.error,
title: errorData.title,
url: errorData.url
}));
}
else {
this.loggerService.error(this.lang.errors.unknownProviderError__i.interpolate({
provider: errorData.provider,
title: errorData.title,
error: errorData.error
}));
}
}
break;
case 'timeout':
{
let timeoutData = (data as ProviderCallbackEventMap['timeout']);
this.loggerService.info(this.lang.info.providerTimeout__i.interpolate({
time: timeoutData.time,
provider: timeoutData.provider
}), { invokeAlert: true, alertTimeout: 3000 });
}
break;
case 'image':
imageQueue.push(null, () => {
let newImage = this.addUniqueImage(imageKeys[i], (data as ProviderCallbackEventMap['image']).content);
if (newImage !== null && this.appSettings.previewSettings.preload)
this.preloadImage(newImage);
this.previewDataChanged.next();
});
break;
case 'completed':
{
if (--numberOfQueriesForImageKey === 0) {
image.retrieving = false;
}
if (--this.previewVariables.numberOfQueriedImages === 0) {
this.loggerService.info(this.lang.info.allImagesRetrieved, { invokeAlert: true, alertTimeout: 3000 });
}
this.previewDataChanged.next();
}
break;
default:
break;
}
});
}
}
}
}
this.previewDataChanged.next();
if (allImagesRetrieved) {
this.loggerService.info(this.lang.info.allImagesRetrieved, { invokeAlert: true, alertTimeout: 3000 });
}
}
else
this.previewDataChanged.next();
}
开发者ID:kencinder,项目名称:steam-rom-manager,代码行数:92,代码来源:preview.service.ts
注:本文中的async.queue函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论