"use strict"; const AsyncFunction = async function () { }.constructor; class Operation { static #operations = new Map(); static #id = 0; static get nextId() { return ++Operation.#id; } static addOperation(id, callback) { Operation.#operations.set(id, callback); } } function discard(target, card) { console.log("DIS!CAR!D!"); postMessage({ type: "game", game: { command: "discard", target: target, card: card } }); } /* function selectUser(from, callback) { const opeId = Operation.nextId; postMessage({ type: "game", game: { command: "selectUser", from: from, id: opeId } }); Operation.addOperation(opeId, callback); }*/ function selectCards(count, target, targetStockId, callback) {/*todo*/ const opeId = Operation.nextId; postMessage({ type: "game", game: { command: "selectCards", target: target, count: count, targetStockId: targetStockId, id: opeId } }); Operation.addOperation(opeId, callback); } function getCard(target, cardId) { return target.cards.find(it => it.cardType.id == cardId); } async function wait(time) { await new Promise(resolve => { setTimeout(resolve, time); }); } onmessage = async e => { console.log(e); switch (e.data.type) { case "run": let fun = new AsyncFunction("target", "players", e.data.function); await fun(e.data.target, e.data.players); break; } }