Source: msg/SimpleMailBox.js

import beof from 'beof';
import Promise from 'Promise';
import MailBox from './MailBox';
import Envelope from './Envelope';

/**
 * SimpleMailBox is a simple no bacchanal MailBox. Nothing
 * special but enqueue and dequeue behaviour.
 * @param {EnqueueListener} enqueueListener - The EnqueueListener that will be notified.
 * @implements {MailBox}
 */
class SimpleMailBox {

    constructor(enqueueListener) {

        beof({ enqueueListener }).interface(MailBox.EnqueueListener);
        this._messages = [];
        this._enqueueListener = enqueueListener;

    }

    enqueue(to, from, message) {

        this._messages.push(new Envelope(to, form, message));
        this._enqueueListener.onEnqueue(this);

    }

    dequeue() {

        if (this._messages.length > 0)
            return this._messages.shift();

        return null;

    }


}

export default SimpleMailBox