import { TaskStore } from './task_store' ; import { ConcreteTaskInstance } from './task' ; import { Updatable } from './task_running' ; import { createBuffer , Operation , BufferOptions } from './lib/bulk_operation_buffer' ; import { unwrapPromise } from './lib/result_type' ; const DEFAULT_BUFFER_MAX_DURATION = 50 ; export class BufferedTaskStore implements Updatable { private bufferedUpdate : Operation < ConcreteTaskInstance , Error > ; constructor ( private readonly taskStore , options ) { this . bufferedUpdate = createBuffer < ConcreteTaskInstance , Error > ( ( docs ) => taskStore . bulkUpdate ( docs ) , { bufferMaxDuration : DEFAULT_BUFFER_MAX_DURATION , ... options , } ) ; } public async update ( doc ) { return unwrapPromise ( this . bufferedUpdate ( doc ) ) ; } public async remove ( id ) { return this . taskStore . remove ( id ) ; } }