Skip to content

Instantly share code, notes, and snippets.

@aep
Created July 17, 2020 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aep/a90a75a71a777f3b3e8d005506af82b8 to your computer and use it in GitHub Desktop.
Save aep/a90a75a71a777f3b3e8d005506af82b8 to your computer and use it in GitHub Desktop.
using async;
using time;
using buffer;
using err;
using log;
export fn main() -> int {
new+1000 e = err::make();
new+64 driver = async::system(&e);
e.abort();
new input = async::stdio::stdin(&e);
e.abort();
new output = async::stdio::stdout(&e);
e.abort();
new read = async::future(&driver);
new write = async::future(&driver);
new+1000 mem = buffer::make();
input.read(&e, &mem, &read);
e.abort();
for (;;) {
log::info(".");
if read.state == async::State::Ready {
log::info("GOTZ STDIN %s", mem.cstr());
read.clear();
output.write(&e, mem.slice(), &write);
e.abort();
}
if write.state == async::State::Ready {
write.clear();
input.read(&e, mem.mut_slice(), &read);
e.abort();
}
driver.wait(&e);
e.abort();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment