Skip to content

Commit

Permalink
WIP base.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
josePereiro committed Oct 16, 2024
1 parent 1c5883c commit d5f9c8a
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/3.AbstractBlobBase/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,32 @@ Base.get!(f::Function, b::AbstractBlob, key) = Base.get!(f, getframe!(b), key)

## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# TODO: Move to Absttract
# :set! :get :get! :dry
# :set! :get! :dry
# all in ram
function withblob!(f::Function, rb::AbstractBlob, mode::Symbol, frame, key::String)
function withblob!(f::Function, b::AbstractBlob, mode::Symbol, frame, key::String)
if mode == :set!
val = f()
setindex!(rb, val, frame, key)
return blobyref(rb, frame, key; rT = typeof(val))
end
if mode == :get
val = get(f, rb, frame, key)
return blobyref(rb, frame, key; rT = typeof(val))
setindex!(b, val, frame, key)
return blobyref(b, frame, key; rT = typeof(val))
end
# TODO: Think about it
# What to do if 'frame, key' is missing
# if mode == :get
# val = get(f, b, frame, key)
# return blobyref(b, frame, key; rT = typeof(val))
# end
if mode == :get!
val = get!(f, rb, frame, key)
return blobyref(rb, frame, key; rT = typeof(val))
val = get!(f, b, frame, key)
return blobyref(b, frame, key; rT = typeof(val))
end
if mode == :dry
val = f()
return blobyref(rb, frame, key; rT = typeof(val))
return blobyref(b, frame, key; rT = typeof(val))
end
error("Unknown mode, ", mode, ". see withblob! src")
end
withblob!(f::Function, rb::AbstractBlob, mode::Symbol, key::String) =
withblob!(f, rb, mode, BLOBBATCH_DEFAULT_FRAME_NAME, key)
withblob!(f::Function, b::AbstractBlob, mode::Symbol, key::String) =
withblob!(f, b, mode, BLOBBATCH_DEFAULT_FRAME_NAME, key)


## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
Expand All @@ -68,19 +70,19 @@ getframe(b::AbstractBlob) = getframe(b, BLOBBATCH_DEFAULT_FRAME_NAME)
## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# lock
import Base.lock
Base.lock(f::Function, rb::AbstractBlob; kwargs...) = _lock(f, rb; kwargs...)
Base.lock(rb::AbstractBlob; kwargs...) = _lock(rb; kwargs...)
Base.lock(f::Function, b::AbstractBlob; kwargs...) = _lock(f, b; kwargs...)
Base.lock(b::AbstractBlob; kwargs...) = _lock(b; kwargs...)

import Base.islocked
Base.islocked(rb::AbstractBlob) = _islocked(rb)
Base.islocked(b::AbstractBlob) = _islocked(b)

import Base.unlock
Base.unlock(rb::AbstractBlob; force = false) = _unlock(rb; force)
Base.unlock(b::AbstractBlob; force = false) = _unlock(b; force)

## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
# blobyref
blobyref(rb::AbstractBlob, key; rT = nothing) =
blobyref(rb, BLOBBATCH_DEFAULT_FRAME_NAME, key; rT)
blobyref(b::AbstractBlob, key; rT = nothing) =
blobyref(b, BLOBBATCH_DEFAULT_FRAME_NAME, key; rT)


## --.--. - .-. .- .--.-.- .- .---- ... . .-.-.-.-
Expand Down

0 comments on commit d5f9c8a

Please sign in to comment.