Giter VIP home page Giter VIP logo

opentrick.jl's Introduction

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

opentrick.jl's People

Contributors

christopher-dg avatar zhanglix avatar

Stargazers

 avatar  avatar

Watchers

 avatar

opentrick.jl's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.