本文整理汇总了TypeScript中async.AsyncQueue.push方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AsyncQueue.push方法的具体用法?TypeScript AsyncQueue.push怎么用?TypeScript AsyncQueue.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类async.AsyncQueue
的用法示例。
在下文中一共展示了AsyncQueue.push方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Error
/**
* Get a single object by its id
*
* @param {string} objectType - E.g. Person
* @param {string}objectId - E.g. 52259f95dafd757b06002221
* @param {object} [params={}] - key/value store for extra arguments like fields, limit, page and/or sort
* @param {string|null} [versionId=null] - optional versionId to retrieve
* @returns {Promise} - for object: a key/value object with object data
*/
getById<T extends CommunibaseDocument = CommunibaseDocument>(
objectType: CommunibaseEntityType,
objectId: string,
params?: CommunibaseParams,
versionId?: string,
): Promise<T> {
if (typeof objectId !== 'string' || objectId.length !== 24) {
return Promise.reject(new Error('Invalid objectId'));
}
// not combinable...
if (versionId || (params && params.fields)) {
const deferred = defer();
this.queue.push({
deferred,
url: `${this.serviceUrl + objectType}.json/${versionId ?
`history/${objectId}/${versionId}` :
`crud/${objectId}`}`,
options: {
method: 'GET',
query: params,
},
});
return deferred.promise;
}
// cached?
if (this.cache && this.cache.isAvailable(objectType, objectId)) {
return this.cache.objectCache[objectType][objectId] as Promise<T>;
}
// since we are not requesting a specific version or fields, we may combine the request..?
if (this.getByIdQueue[objectType] === undefined) {
this.getByIdQueue[objectType] = {};
}
if (this.getByIdQueue[objectType][objectId]) {
// requested twice?
return this.getByIdQueue[objectType][objectId].promise;
}
this.getByIdQueue[objectType][objectId] = defer();
if (this.cache) {
if (this.cache.objectCache[objectType] === undefined) {
this.cache.objectCache[objectType] = {};
}
this.cache.objectCache[objectType][objectId] = this.getByIdQueue[objectType][objectId].promise;
}
if (!this.getByIdPrimed) {
process.nextTick(() => {
this.spoolQueue();
});
this.getByIdPrimed = true;
}
return this.getByIdQueue[objectType][objectId].promise;
}
示例2: finalizeInvoice
/**
* Finalize an invoice by its ID
*
* @param invoiceId
* @returns {*}
*/
public finalizeInvoice(invoiceId:string) : Promise<CommunibaseDocument> {
const deferred = defer();
this.queue.push({
deferred,
url: `${this.serviceUrl}Invoice.json/finalize/${invoiceId}`,
options: {
method: 'POST',
},
});
return deferred.promise;
}
示例3: getHistory
/**
* Get the history information for a certain type of object
*
* VersionInformation: {
* "_id": "ObjectId",
* "updatedAt": "Date",
* "updatedBy": "string"
* }
*
* @param {string} objectType
* @param {string} objectId
* @returns promise for VersionInformation[]
*/
public getHistory(objectType:CommunibaseEntityType, objectId: string):Promise<CommunibaseVersionInformation[]> {
const deferred = defer();
this.queue.push({
deferred,
url: `${this.serviceUrl + objectType}.json/history/${objectId}`,
options: {
method: 'GET',
},
});
return deferred.promise;
}
示例4: historySearch
/**
*
* @param {string} objectType
* @param {Object} selector
* @returns promise for VersionInformation[]
*/
public historySearch(objectType: CommunibaseEntityType, selector: {}):Promise<CommunibaseVersionInformation[]> {
const deferred = defer();
this.queue.push({
deferred,
url: `${this.serviceUrl + objectType}.json/history/search`,
options: {
method: 'POST',
body: JSON.stringify(selector),
},
});
return deferred.promise;
}
示例5: undelete
/**
* Undelete something from Communibase
*
* @param objectType
* @param objectId
* @returns promise (for null)
*/
public undelete(objectType: CommunibaseEntityType, objectId: string):Promise<CommunibaseDocument> {
const deferred = defer();
this.queue.push({
deferred,
url: `${this.serviceUrl + objectType}.json/history/undelete/${objectId}`,
options: {
method: 'POST',
},
});
return deferred.promise;
}
示例6: defer
/**
* Get all objects of a certain type
*
* @param {string} objectType - E.g. Person
* @param {object} [params={}] - key/value store for extra arguments like fields, limit, page and/or sort
* @returns {Promise} - for array of key/value objects
*/
public getAll<T extends CommunibaseDocument = CommunibaseDocument>
(objectType: CommunibaseEntityType, params?: CommunibaseParams):Promise<T[]> {
if (this.cache && !(params && params.fields)) {
return this.search<T>(objectType, {}, params);
}
const deferred = defer();
this.queue.push({
deferred,
url: `${this.serviceUrl + objectType}.json/crud`,
options: {
method: 'GET',
query: params,
},
});
return deferred.promise;
}
示例7: destroy
/**
* Delete something from Communibase
*
* @param objectType
* @param objectId
* @returns promise (for null)
*/
public destroy(objectType: CommunibaseEntityType, objectId: string):Promise<null> {
const deferred = defer();
if (this.cache && this.cache.objectCache && this.cache.objectCache[objectType] &&
this.cache.objectCache[objectType][objectId]) {
this.cache.objectCache[objectType][objectId] = null;
}
this.queue.push({
deferred,
url: `${this.serviceUrl + objectType}.json/crud/${objectId}`,
options: {
method: 'DELETE',
},
});
return deferred.promise;
}
示例8: getResourceBufferPromise
return getResourceBufferPromise(resource).then((buffer:any) => {
if (id) { // TODO check is valid id? entails extra dependency (mongodb.ObjectID)
// update File identified by id
return this.update('File', {
_id: id,
filename: name,
length: buffer.length,
uploadDate: moment().format(),
metadata: metaData,
content: buffer,
});
}
// create a new File
const deferred = defer();
const formData:FormData = new FormData();
let stringOrBlob:string|Blob = buffer;
// @see https://developer.mozilla.org/en-US/docs/Web/API/FormData/append
// officially, formdata may contain blobs or strings. node doesn't do blobs, but when polymorphing in a browser we
// may cast it to one for it to work properly...
if (typeof window !== 'undefined' && window.Blob) {
stringOrBlob = new Blob([buffer]);
}
formData.append('File', stringOrBlob, name);
formData.append('metadata', JSON.stringify(metaData));
this.queue.push({
deferred,
url: `${this.serviceUrl}File.json/binary`,
options: {
method: 'POST',
body: formData,
headers: {
Accept: 'application/json',
},
},
});
return deferred.promise;
});