ContextManagers.jl

Author JuliaPreludes
Popularity
4 Stars
Updated Last
1 Year Ago
Started In
August 2021

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: