# SPDX-FileCopyrightText: ☭ Emery Hemingway # SPDX-License-Identifier: Unlicense import std/[oserrors, parseopt, posix, strutils] import pkg/sys/[files, handles, ioqueue] import preserves, syndicate, syndicate/relays type Present {.preservesRecord: "Present".} = object username: string Says {.preservesRecord: "Says".} = object who, what: string proc syncAndStop(facet: Facet; cap: Cap) = ## Stop the actor responsible for `facet` after ## synchronizing with `cap`. run(facet) do (turn: var Turn): sync(turn, cap, stopActor) proc readStdin(facet: Facet; ds: Cap; username: string) {.asyncio.} = let fd = stdin.getOsFileHandle() flags = fcntl(fd.cint, F_GETFL, 0) if flags < 0: raiseOSError(osLastError()) if fcntl(fd.cint, F_SETFL, flags or O_NONBLOCK) < 0: raiseOSError(osLastError()) let file = newAsyncFile(FD fd) buf = new string buf[].setLen(0x1000) while true: let n = read(file, buf) if n < 1: stderr.writeLine "test_chat calls stopsActor ", facet.actor syncAndStop(facet, ds) return else: var msg = buf[][0..