import PQueue from 'p-queue/dist' ; import pRetry = require ( 'p-retry' ) ; import { PHConfig , QueueConfig , RetryConfig } from './ph-config' ; declare type Task < TaskResultType > = ( ( ) => PromiseLike < TaskResultType > ) | ( ( ) => TaskResultType ) ; export default class PromiseHandler { private queue : PQueue ; private queueConfig : QueueConfig ; private retryConfig : RetryConfig ; constructor ( config ? ) { this . queueConfig = { ... new QueueConfig ( ) , ... config ?. queue , } ; this . retryConfig = { ... new RetryConfig ( ) , ... config ?. retry , } ; this . queue = new PQueue ( this . queueConfig ) ; } add < TaskResultType > ( fn ) { return this . queue . add ( async ( ) => await pRetry ( fn , this . retryConfig ) ) ; } getQueue ( ) { return this . queue ; } getQueueConfig ( ) { return this . queueConfig ; } getRetryConfig ( ) { return this . retryConfig ; } }