INNER CODE UNIT · JavaScript
sendCommand
sebastiancarlos/beachpatrol · beachmsg.js:44
const sendCommand = async function* (endpoint, command, { timeout } = {}) {
const client = connect(endpoint, () => {
client.write(JSON.stringify(command));
});
const rl = createInterface({ input: client });
// Stop iteration after timeout, if any.
let timedOut = false;
let timer;
if (timeout) {
timer = setTimeout(() => {
timedOut = true;
rl.close();
}, timeout);
}
try {
for await (const line of rl) {