dummy-link

Readme

OpenTrick

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.

Examples

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

Supported Interfaces in Base

  • read, read!, readbytes!, unsafe_read, readavailable, readline, readlines, eachline, readchomp, readuntil, bytesavailable
  • write, unsafe_write, truncate, flush, print, println, printstyled, showerror
  • seek, seekstart, seekend, skip, skipchars, position
  • mark, unmark, reset, ismarked
  • isreadonly, iswritable, isreadable, isopen, eof
  • countlines, displaysize

OpenTrick.jl Documentation

# OpenTrick.opentrickFunction.

opentrick(openfn[, args... [; <keyword arguments>]])

Call openfn with (handlefn, args... ,kwargs ...) as arguments, return an IOWrapper instance. (NB:handlefn is provided by opentrick.)

Arguments

  • openfn::Function function actually called to obtain a IO instance. openfn must take a Function(::IO) instance as its first argument
  • args optional arguments that will be passed to openfn
  • kwargs optional keyword arguments that will be passed to openfn

Examples

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!"

source

# OpenTrick.rawioFunction.

rawio(io)

Return the actual io instance

source

# OpenTrick.blockingtaskFunction.

blockingtask(io)

Return the task blocking which prevents the handlefn passed to openfn from returning

source

# OpenTrick.unsafe_clearFunction.

unsafe_clear()

Unblock all blocking tasks. All ios returned by opentrick will be closed as a consequence.

source

First Commit

09/20/2018

Last Touched

about 2 years ago

Commits

29 commits

Requires:

Used By: