import sleep from "utils/sleep" ; import { Operation } from "../types" ; class OperationHandler { public async load ( operations , handler ) { await Promise . all ( operations . map ( async ( operation , index ) => { try { await this . handleOperation ( operation , index ) ; } catch ( error ) { console . error ( `Cannot complete operation: "${ operation . name }"` , error ) ; } handler ( operation . name ) ; } ) ) ; } private async handleOperation ( operation , index ) { await sleep ( 100 * index ) ; await operation . method ( ) ; } } export default OperationHandler ;