standard-procedure-plumbing 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +2 -81
- data/README.md +316 -113
- data/checksums/standard-procedure-plumbing-0.2.2.gem.sha512 +1 -0
- data/checksums/standard-procedure-plumbing-0.3.0.gem.sha512 +1 -0
- data/lib/plumbing/config.rb +51 -0
- data/lib/plumbing/custom_filter.rb +15 -0
- data/lib/plumbing/error.rb +0 -6
- data/lib/plumbing/event.rb +1 -2
- data/lib/plumbing/filter.rb +10 -11
- data/lib/plumbing/junction.rb +4 -5
- data/lib/plumbing/pipe.rb +26 -26
- data/lib/plumbing/pipeline/contracts.rb +13 -3
- data/lib/plumbing/pipeline/operations.rb +19 -2
- data/lib/plumbing/pipeline.rb +3 -0
- data/lib/plumbing/rubber_duck/object.rb +11 -0
- data/lib/plumbing/rubber_duck/proxy.rb +19 -0
- data/lib/plumbing/rubber_duck.rb +59 -0
- data/lib/plumbing/types.rb +6 -0
- data/lib/plumbing/valve/async.rb +42 -0
- data/lib/plumbing/valve/inline.rb +19 -0
- data/lib/plumbing/valve/message.rb +5 -0
- data/lib/plumbing/valve.rb +71 -0
- data/lib/plumbing/version.rb +1 -1
- data/lib/plumbing.rb +11 -9
- metadata +14 -4
- data/lib/plumbing/event_dispatcher/fiber.rb +0 -61
- data/lib/plumbing/event_dispatcher.rb +0 -35
@@ -1,61 +0,0 @@
|
|
1
|
-
require "async/task"
|
2
|
-
require "async/semaphore"
|
3
|
-
|
4
|
-
module Plumbing
|
5
|
-
class EventDispatcher
|
6
|
-
class Fiber < EventDispatcher
|
7
|
-
def initialize limit: 4
|
8
|
-
super()
|
9
|
-
@semaphore = Async::Semaphore.new(limit)
|
10
|
-
@queue = Set.new
|
11
|
-
@paused = false
|
12
|
-
end
|
13
|
-
|
14
|
-
def dispatch event
|
15
|
-
@queue << event
|
16
|
-
dispatch_events unless @paused
|
17
|
-
end
|
18
|
-
|
19
|
-
def pause
|
20
|
-
@paused = true
|
21
|
-
end
|
22
|
-
|
23
|
-
def resume
|
24
|
-
@paused = false
|
25
|
-
dispatch_events
|
26
|
-
end
|
27
|
-
|
28
|
-
def queue_size
|
29
|
-
@queue.size
|
30
|
-
end
|
31
|
-
|
32
|
-
def shutdown
|
33
|
-
super
|
34
|
-
@queue.clear
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def dispatch_events
|
40
|
-
@semaphore.async do |task|
|
41
|
-
events = @queue.dup
|
42
|
-
@queue.clear
|
43
|
-
events.each do |event|
|
44
|
-
dispatch_event event, task
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def dispatch_event event, task
|
50
|
-
@observers.collect do |observer|
|
51
|
-
task.async do
|
52
|
-
observer.call event
|
53
|
-
rescue => ex
|
54
|
-
puts ex
|
55
|
-
ex
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Plumbing
|
2
|
-
class EventDispatcher
|
3
|
-
def initialize observers: []
|
4
|
-
@observers = observers
|
5
|
-
end
|
6
|
-
|
7
|
-
def add_observer observer = nil, &block
|
8
|
-
observer ||= block.to_proc
|
9
|
-
raise Plumbing::InvalidObserver.new "observer_does_not_respond_to_call" unless observer.respond_to? :call
|
10
|
-
@observers << observer
|
11
|
-
observer
|
12
|
-
end
|
13
|
-
|
14
|
-
def remove_observer observer
|
15
|
-
@observers.delete observer
|
16
|
-
end
|
17
|
-
|
18
|
-
def is_observer? observer
|
19
|
-
@observers.include? observer
|
20
|
-
end
|
21
|
-
|
22
|
-
def dispatch event
|
23
|
-
@observers.collect do |observer|
|
24
|
-
observer.call event
|
25
|
-
rescue => ex
|
26
|
-
puts ex
|
27
|
-
ex
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def shutdown
|
32
|
-
@observers = []
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|