There are some
open methods which only support the
open() do io ... end conventions. This module provides a trick to enable keeping
io for later usage. This is convenient for interactive programming.
using WebSockets as an example.
using OpenTrick using WebSockets io = opentrick(WebSockets.open, "ws://echo.websocket.org"); write(io, "Hello"); println(String(read(io))); close(io) # you can close io manually io = nothing; # or leave it to GC unsafe_clear() # or you can clear all ios opened by opentrick manually
OpenTrick.opentrick — Function.
opentrick(openfn[, args... [; <keyword arguments>]])
(handlefn, args... ,kwargs ...) as arguments, return an
IOWrapper instance. (NB:
handlefn is provided by
openfn::Functionfunction actually called to obtain a
openfnmust take a
Function(::IO)instance as its first argument
argsoptional arguments that will be passed to
kwargsoptional keyword arguments that will be passed to
julia> using OpenTrick julia> filename = tempname(); julia> io = opentrick(open, filename, "w+"); julia> write(io, "hello world!") 12 julia> seek(io, 0); julia> readline(io) "hello world!"
OpenTrick.rawio — Function.
Return the actual
OpenTrick.blockingtask — Function.
Return the task blocking which prevents the
handlefn passed to
openfn from returning
OpenTrick.unsafe_clear — Function.
Unblock all blocking tasks. All
ios returned by
opentrick will be closed as a consequence.
about 2 years ago