# --- Pipeline implementation matching Go semantics ---
#
# Go behavior (from provided code):
# - Pipeline has Stash(name, bytes) which stores bytes by name.
# - Pipeline has UnStash(name) which returns bytes previously stashed.
#
# Here we implement an in-memory Pipeline that stores artifacts in a Hash(String, Bytes).
# This preserves the same behavior and API as the Go code used in the original snippet.
class Pipeline
getter id : String
def initialize(@id : String)
@artifacts = {} of String => Bytes
@mutex = Mutex.new
end
# get_artifact(name) corresponds to Go's UnStash(name) -> ([]byte, error)
# Returns Bytes? (nil if not found)
def get_artifact(name : String) : Bytes?
@mutex.synchronize do
@artifacts[name]
end
end
# set_artifact(name, data) corresponds to Go's Stash(name, bytes)
def set_artifact(name : String, data : Bytes)
@mutex.synchronize do
# store a copy to mimic Go's slice ownership semantics
@artifacts[name] = data.to_slice
end
nil
end
end