File: atomic_example.rb

package info (click to toggle)
ruby-concurrent 1.1.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 30,284 kB
  • sloc: ruby: 30,875; java: 6,117; ansic: 288; makefile: 9; sh: 6
file content (16 lines) | stat: -rwxr-xr-x 392 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env ruby

#$: << File.expand_path('../../lib', __FILE__)

require 'concurrent/atomics'

my_atomic = Concurrent::AtomicReference.new(0)
my_atomic.update {|v| v + 1}
puts "new value: #{my_atomic.value}"

begin
  my_atomic.try_update {|v| v + 1}
rescue Concurrent::Atomic::ConcurrentUpdateError => cue
  # deal with it (retry, propagate, etc)
end
puts "new value: #{my_atomic.value}"