sendAsync()

in remote/communicator.js [262:308]


    sendAsync(path, content) {
        this.validateDisposal();

        if (utils.string.isEmptyOrWhitespace(path)) {
            throw new Error("path must be a string and not empty/whitespaces.");
        }

        return new Promise((resolve, reject) => {
            /** @type {Donuts.Remote.IMessage} */
            const msg = {
                id: random.generateUid(8),
                sender: this.id,
                timestamp: Date.now(),
                path: path,
                body: content
            };

            Log.writeInfoAsync("{} REMOTE {,7} {} => {}", msg.sender, Action.Send, msg.id, msg.path);
            this.channelProxy.sendData(msg);

            if (this.timeout) {
                setTimeout(
                    (msgId) => {
                        const record = this.ongoingPromiseDict[msg.id];

                        if (!record) {
                            return;
                        }

                        record.reject(new Error(`Communicator-${this.id}: Message, ${msgId}, timed out (${this.timeout}).`));
                    },
                    this.timeout,
                    msg.id);
            }

            this.ongoingPromiseDict[msg.id] = {
                resolve: (result) => {
                    Log.writeInfoAsync("{} REMOTE {,7} {} ~{,4:F0}ms => {}", msg.sender, Action.Sent, msg.id, Date.now() - msg.timestamp, msg.path);
                    resolve(result);
                },
                reject: (error) => {
                    Log.writeErrorAsync("{} REMOTE {,7} {} ~{,4:F0}ms: {}", msg.sender, Action.Failed, msg.id, Date.now() - msg.timestamp, error);
                    reject(error);
                }
            };
        });
    }