8,037 Matching Annotations
  1. May 2023
    1. ```ts

      /* * Initiates a connection to the selected port. / async function connectToServer(): Promise<void> { hostInput.disabled = true; portInput.disabled = true; connectButton.textContent = 'Connecting...'; connectButton.disabled = true;

      try { socket = new TCPSocket(hostInput.value, parseInt(portInput.value)); connection = await socket.opened; term.writeln('<CONNECTED>'); connectButton.textContent = 'Disconnect'; connectButton.disabled = false; } catch (e) { console.error(e); term.writeln(<ERROR: ${e.message}>); markDisconnected(); return; }

      try { reader = connection?.readable.getReader(); for (;;) { const {value, done} = await reader.read(); if (value) { await new Promise<void>((resolve) => { term.write(value, resolve); }); } if (done) { break; } } reader.releaseLock(); reader = undefined; } catch (e) { console.error(e); term.writeln(<ERROR: ${e.message}>); }

      markDisconnected(); }

      /* * Closes the currently active connection. / async function disconnectFromServer(): Promise<void> { // Canceling |reader| will close the connection and cause the read loop in // connectToServer() to exit when read() returns with done set to true. if (reader) { await reader.cancel(); } } ```

  2. Apr 2023
    1. Publish (on your) Own Site, Syndicate Elsewhere

      Publish (on your) Own Site, Spam Everywhere