UNPKG

@livy/util

Version:
36 lines (35 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractBatchHandler = void 0; const is_sync_handler_interface_1 = require("./is-sync-handler-interface"); /** * Base Handler class providing `handleBatch` and `handleBatchSync` * by sequentially hanlding records * * Note that `handleBatchSync` is a no-op as long as no `handleSync` * is implemented by classes extending this handler. */ class AbstractBatchHandler { /** * @inheritdoc */ async handleBatch(records) { for (const record of records) { await this.handle(record); } } /** * Handles a set of records at once. * * @param records The records to handle (an array of record arrays) */ handleBatchSync(records) { if (!(0, is_sync_handler_interface_1.isSyncHandlerInterface)(this)) { throw new Error('Cannot invoke handleBatchSync() on an asynchronous handler'); } for (const record of records) { this.handleSync(record); } } } exports.AbstractBatchHandler = AbstractBatchHandler;