<commit_before>import { ReactiveVar } from 'meteor/reactive-var';

export class Result {
    constructor({
        observer,
        defaultValue = {}
    } = {}) {
        this.observer = observer;

        this._isReady = new ReactiveVar(false);
        this._errors = new ReactiveVar();
        this._var = new ReactiveVar(defaultValue);

        this.subscribe();
    }

    isReady() {
        return this._isReady.get();
    }

    get() {
        return this._var.get();
    }

    getErrors() {
        return this._errors.get();
    }

    unsubscribe() {
        return this._subscription && this._subscription.unsubscribe();
    }

    subscribe() {
        if (this._subscription) {
            this.unsubscribe();
        }

        this._subscription = this.observer.subscribe({
            next: ({ errors, data }) => {
                if (errors) {
                    this._errors.set(errors);
                } else {
                    this._errors.set(null);
                    this._var.set(data);
                }
                this._isReady.set(true);
            }
        });
    }
}<commit_msg>Add some basic error handling<commit_after>import { ReactiveVar } from 'meteor/reactive-var';

export class Result {
    constructor({
        observer,
        defaultValue = {}
    } = {}) {
        this.observer = observer;

        this._isReady = new ReactiveVar(false);
        this._errors = new ReactiveVar();
        this._var = new ReactiveVar(defaultValue);

        this.subscribe();
    }

    isReady() {
        return this._isReady.get();
    }

    get() {
        return this._var.get();
    }

    getErrors() {
        return this._errors.get();
    }

    unsubscribe() {
        return this._subscription && this._subscription.unsubscribe();
    }

    subscribe() {
        if (this._subscription) {
            this.unsubscribe();
        }

        this._subscription = this.observer.subscribe({
            next: ({ errors, data }) => {
                if (errors) {
                    this._errors.set(errors);
                } else {
                    this._errors.set(null);
                    this._var.set(data);
                }
                this._isReady.set(true);
            },
            error: (error) => {
                this._errors.set([].concat(error));
                this._isReady.set(true);
            }
        });
    }
}
{'fraction_non_alphanumeric': 0.12926018287614296, 'fraction_numerical': 0.0, 'mean_word_length': 1.4288597376387486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5765630', 'n_tokens_mistral': 675, 'n_tokens_neox': 641, 'n_words': 110}