JuliaGeo / Proj.jl

Julia wrapper for the PROJ cartographic projections library
MIT License
48 stars 9 forks source link

Add with_network do block #89

Closed visr closed 1 year ago

visr commented 1 year ago

I think this may be useful, at least for testing purposes, a do-block that turns on the network, and puts it back to the original setting when it finishes.

function with_network(f::Function; ctx::Ptr{Proj.PJ_CONTEXT} = C_NULL)
    as_before = Proj.network_enabled(ctx)
    Proj.enable_network!(true, ctx)
    try
        f()
    finally
        Proj.enable_network!(as_before, ctx)
    end
end

Proj.enable_network!()
Proj.enable_network!(false)
Proj.network_enabled()

with_network() do
    @show Proj.network_enabled()
end