xunfeiAI/node_modules/miniprogram-queue/es/index.d.ts

144 lines
3.6 KiB
TypeScript
Raw Normal View History

2023-09-12 20:19:08 +08:00
/// <reference lib="es6" />
/**
*
* @example var rq = new WxQueue(wx.requst);
* @template TParam
* @template TTask task类型
*/
export declare class WxQueue<TParam extends BaseOption, TTask extends BaseTask> {
/**
*
*/
readonly MAX: number;
/**
* ID计数器
*/
private taskid;
/**
*
*/
private readonly todo;
/**
*
*/
private readonly taskMap;
/**
* API
*/
private readonly operator;
/**
* Wx操作队列
* @param wxFunc Wx操作函数
* @param maxLength 10
*/
constructor(wxFunc: (params: TParam) => TTask, maxLength?: number);
/**
*
* @param param
*/
push(param: QueueOption<TParam>): TTask;
/**
* check and do next task
*/
private _next;
/**
* process a task
* @param id task ID
* @param options task param
*/
private _process;
/**
* stop and remove a task
* @param taskid - the id of task to abort
*/
private _abort;
/**
* progress update callback
* https://developers.weixin.qq.com/miniprogram/dev/api/network/download/DownloadTask.onProgressUpdate.html
* @param taskid - task id
* @param callback
*/
private _onProgress;
private _onHeaders;
}
export declare type QueueOption<T> = T & ExtraOptions;
/**
*
*/
interface ExtraOptions {
/**
* progress
*/
onProgressUpdate?: wx.UploadTaskOnProgressUpdateCallback | wx.DownloadTaskOnProgressUpdateCallback;
/**
*
*/
jump?: boolean;
/**
*
*/
timeout?: number;
/**
*
*/
timestamp?: boolean | object;
/**
* HTTP Response Header
*/
onHeadersReceived?(result: {
header: object;
}): void;
}
interface BaseOption {
/** 开发者服务器接口地址 */
url: string;
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: Function;
/** 接口调用失败的回调函数 */
fail?: Function;
/** 接口调用成功的回调函数 */
success?: Function;
}
interface BaseTask {
abort(): void;
/** HTTP Response Header 事件的回调函数 */
onHeadersReceived(callback: ExtraOptions['onHeadersReceived']): void;
/** 下载进度变化事件的回调函数 */
onProgressUpdate?(callback: ExtraOptions['onProgressUpdate']): void;
}
declare namespace wx {
type UploadTaskOnProgressUpdateCallback = (res: {
/**
*
*/
progress: number;
/**
* Bytes
*/
totalBytesSent: number;
/**
* Bytes
*/
totalBytesExpectedToSend: number;
}) => void;
type DownloadTaskOnProgressUpdateCallback = (res: {
/**
*
*/
progress: number;
/**
* Bytes
*/
totalBytesWritten: number;
/**
* Bytes
*/
totalBytesExpectedToWrite: number;
}) => void;
}
export interface TimeRecorder {
send?: number;
response?: number;
}
export {};
//# sourceMappingURL=index.d.ts.map