<commit_before>/**
 * @author <NAME> <<EMAIL>>
 */

import { NoelEvent, NoelEventListenerManager } from './interfaces';
import { NoelEventListener } from './types';

export class NoelEventListenerManagerImp implements NoelEventListenerManager {
    constructor(private listener: NoelEventListener, private event: NoelEvent) {}

    remove() {
        return this.event.removeListener(this.listener);
    }

    replay(bufferSize: number): NoelEventListenerManager {
        const eventReplayBuffer = this.event.getReplayBufferAmount(bufferSize);
        eventReplayBuffer.forEach(eventReplayBufferItem => {
            this.listener(...eventReplayBufferItem);
        });
        return this;
    }
}<commit_msg>feat(event-listener-manager): warn if attempt to replay more than buffer can contain<commit_after>/**
 * @author <NAME> <<EMAIL>>
 */

import { NoelEventListenerManager } from './interfaces';
import { NoelEventListener } from './types';
import { NoelEventImp } from './event';
import { NoelEventReplayNotEnabled } from './errors';

export class NoelEventListenerManagerImp implements NoelEventListenerManager {
    constructor(private listener: NoelEventListener, private event: NoelEventImp) {}

    remove() {
        return this.event.removeListener(this.listener);
    }

    replay(bufferSize: number): NoelEventListenerManager {
        const event = this.event;
        if (!event.getReplayIsEnabled()) throw new NoelEventReplayNotEnabled(event);
        const actualBufferSize = event.getReplayBufferSize();
        if (bufferSize > actualBufferSize) {
            const logger = event.getLogger();
            logger.warn(`Attempted to replay ${bufferSize} emits from the event "${event.getName()}" but the replay buffer size is set to ${actualBufferSize}.`);
        }
        const eventReplayBuffer = this.event.getReplayBufferAmount(bufferSize);
        eventReplayBuffer.forEach(eventReplayBufferItem => {
            this.listener(...eventReplayBufferItem);
        });
        return this;
    }
}
{'fraction_non_alphanumeric': 0.10962962962962963, 'fraction_numerical': 0.0, 'mean_word_length': 3.6682027649769586, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2860062', 'n_tokens_mistral': 532, 'n_tokens_neox': 523, 'n_words': 126}