/**
 * Typical barrier type.
 *
 * Block all clients until everyone has hit the barrier.
 */
class Barrier {
    constructor() {
        let resolver;
        this.promise = new Promise((resolve) => {
            resolver = resolve;
        });
        this.resolver = resolver;
        this.hits = new Set();
    }

    wait() {
        socket.emit("message", Packet.createBarrierSignal());

        return this.promise;
    }

    resolve(data) {
        this.hits.add(data.author);

        if (this.hits.size === Object.keys(players).length - 1) {
            this.hits = new Set();
            this.resolver();
        }
    }
}
