Asynchronous access to stdin. The constructor is private to ensure that access is provided only via an environment.
Reading from stdin is done by registering an InputNotify
:
actor Main new create(env: Env) => // do not forget to call `env.input.dispose` at some point env.input( object iso is InputNotify fun ref apply(data: Array[U8] iso) => env.out.write(String.from_iso_array(consume data)) fun ref dispose() => env.out.print("Done.") end, 512)
Note: For reading user input from a terminal, use the term package.
actor tag Stdin
Create an asynchronous stdin provider.
new tag _create( use_event: Bool val) : Stdin tag^
Set the notifier. Optionally, also sets the chunk size, dictating the maximum number of bytes of each chunk that will be passed to the notifier.
be apply( notify: (InputNotify iso | None val), chunk_size: USize val = 32)
Clear the notifier in order to shut down input.
be dispose()
If we are able to read from stdin, schedule another read.
be _loop_read()
When the event fires, read from stdin.
be _event_notify( event: Pointer[AsioEvent val] tag, flags: U32 val, arg: U32 val)
Resume reading.
be _read_again()
Set the notifier.
fun ref _set_notify( notify: (InputNotify iso | None val)) : None val
Read a chunk of data from stdin. Read a maximum of _chunk_size bytes, send ourself a resume message and stop reading to avoid starving other actors.
fun ref _read() : Bool val
Close the event.
fun ref _close_event() : None val
© 2016-2018, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/builtin-Stdin