Skip to content

JuliaPreludes/ContextManagers.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ContextManagers

ContextManagers.jl provides composable resource management interface for Julia.

using ContextManagers: @with, opentemp, onexit

lck = ReentrantLock()
ch = Channel()

@with(
    lck,
    (path, io) = opentemp(),
    onexit(lock(ch)) do _
        unlock(ch)
        println("Successfully unlocked!")
    end,
) do
    println(io, "Hello World")
end

# output
Successfully unlocked!

See also: