///
import { EventEmitter } from "events";
import { Method, Body, HTTPHeaders } from "./http";
export declare type TaskType = "request" | "download";
export declare enum Events {
Error = "error",
Complete = "complete"
}
export declare class Task {
type: TaskType;
method: Method;
url: string;
body?: Body;
headers?: HTTPHeaders;
id: number;
constructor(type: TaskType, method: Method, url: string, body?: Body, headers?: HTTPHeaders);
}
export interface Options {
concurrency?: number;
}
declare type SubscribeFn = (task: Task) => Promise;
interface IScheduler extends EventEmitter {
subscribe(fn: SubscribeFn): void;
push(task: Task): void;
clear(): void;
length: number;
}
export declare class Scheduler extends EventEmitter implements IScheduler {
private options;
readonly pendingQueue: Task[];
readonly runningQueue: Task[];
private subscriptionFn;
constructor(options?: Options);
/**
* execute a task
* @param task a task to execute
*/
private exec;
/**
* Is the scheduler busy?
*/
private get isBusy();
/**
* Is the scheduler can go to next task?
*/
private get nextable();
/**
* Go to the next task
*/
private next;
/**
* Subscribe the task
* @param fn
*/
subscribe(fn: SubscribeFn): void;
/**
* Push a new task to the pool
* @param task a new task
*/
push(task: Task): void;
/**
* Clear the pendingQueue
*/
clear(): void;
/**
* Get the length for this scheduler
*/
get length(): number;
}
export {};