* Like emit but receiver can send response * @param {String} event The event descriptor * @param {Object} options (optional) Data to be sent in the event * @param {Object} port (optional) The port to be used. If * not specified, the main port is u
(event, options = {})
| 224 | * @return {Promise} |
| 225 | */ |
| 226 | send(event, options = {}) { |
| 227 | return new Promise((resolve, reject) => { |
| 228 | if (!event || typeof event !== 'string') { |
| 229 | return reject(new Error('Invalid event!')); |
| 230 | } |
| 231 | this.#checkConnection(); |
| 232 | if (!this.#reply) { |
| 233 | this.#reply = new Map(); |
| 234 | } |
| 235 | options.event = event; |
| 236 | options._reply = ++this.#replyCount; |
| 237 | this.#reply.set(options._reply, {resolve, reject}); |
| 238 | this._port.postMessage(options); |
| 239 | }); |
| 240 | } |
| 241 | } |
no test coverage detected