Class: CrossSpec::Spec
- Inherits:
-
Object
- Object
- CrossSpec::Spec
- Defined in:
- lib/cross_spec/spec.rb
Class Method Summary collapse
Instance Method Summary collapse
- #async(service:, data: nil) ⇒ Object
- #await(tasks:, options: {}, &block) ⇒ Object
- #sync(service:, data: nil, tasks:, options: {}, &block) ⇒ Object
Class Method Details
.trace(&block) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/cross_spec/spec.rb', line 48 def self.trace(&block) spec = new DistributedTracing.trace do spec.instance_eval(&block) end end |
Instance Method Details
#async(service:, data: nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cross_spec/spec.rb', line 55 def async(service:, data: nil) DistributedTracing.trace do str = JSON.dump( service: service, biomarkers: DistributedTracing.get, data: data ) CrossSpec.broadcast(str) end nil end |
#await(tasks:, options: {}, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cross_spec/spec.rb', line 72 def await(tasks:, options: {}, &block) combined = { timeout: 5 }.merge() waiting = SpecWaiting.new(tasks) ::Timeout::timeout(combined[:timeout]) do CrossSpec.listen! do || waiting.process(, &block) return waiting.data.length == 1 ? waiting.data.first : waiting.data if waiting.done? nil # nil keeps blocking listen! end end end |
#sync(service:, data: nil, tasks:, options: {}, &block) ⇒ Object
67 68 69 70 |
# File 'lib/cross_spec/spec.rb', line 67 def sync(service:, data: nil, tasks:, options: {}, &block) async(service: service, data: data) await(tasks: tasks, options: , &block) end |