Sha256: d64cc2cdeca2dc225ef991dc89cbaeaf1af10438e0ece9352f551234ce4c5bbf
Contents?: true
Size: 536 Bytes
Versions: 1
Compression:
Stored size: 536 Bytes
Contents
# This is a naively written routine whose intended purpose is to run the provided block at most # once. In a single-threaded application this should work just fine, but if an instance of this # class is shared among several threads who all try to invoke call on it, it will eventually fail at # its intended purpose and execute the provided block more than once. class ThreadUnsafeRunAtMostOnce def initialize(&blk) @blk = blk @ran = false end def call unless @ran @ran = true @blk.call end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
thread_weaver-0.1.0 | examples/thread_unsafe_run_at_most_once.rb |