Skip to content

Commit 39b0aa9

Browse files
committed
Rename hook to handler in AtExit
1 parent 1f3a128 commit 39b0aa9

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

lib/concurrent/at_exit.rb

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@
33

44
module Concurrent
55

6-
# Provides ability to add and remove hooks to be run at `Kernel#at_exit`, order is undefined.
7-
# Each hook is executed at most once.
6+
# Provides ability to add and remove handlers to be run at `Kernel#at_exit`, order is undefined.
7+
# Each handler is executed at most once.
88
class AtExitImplementation < Synchronization::Object
99
include Logging
1010

1111
def initialize(enabled = true)
1212
super()
1313
synchronize do
14-
@hooks = {}
15-
@enabled = enabled
14+
@handlers = {}
15+
@enabled = enabled
1616
end
1717
end
1818

19-
# Add a hook to be run at `Kernel#at_exit`
20-
# @param [Object] hook_id optionally provide an id, if allready present, hook is replaced
21-
# @yield the hook
22-
# @return id of the hook
23-
def add(hook_id = nil, &hook)
24-
id = hook_id || hook.object_id
25-
synchronize { @hooks[id] = hook }
19+
# Add a handler to be run at `Kernel#at_exit`
20+
# @param [Object] handler_id optionally provide an id, if allready present, handler is replaced
21+
# @yield the handler
22+
# @return id of the handler
23+
def add(handler_id = nil, &handler)
24+
id = handler_id || handler.object_id
25+
synchronize { @handlers[id] = handler }
2626
id
2727
end
2828

29-
# Delete a hook by hook_id
29+
# Delete a handler by handler_id
3030
# @return [true, false]
31-
def delete(hook_id)
32-
!!synchronize { @hooks.delete hook_id }
31+
def delete(handler_id)
32+
!!synchronize { @handlers.delete handler_id }
3333
end
3434

35-
# Is hook with hook_id rpesent?
35+
# Is handler with handler_id rpesent?
3636
# @return [true, false]
37-
def hook?(hook_id)
38-
synchronize { @hooks.key? hook_id }
37+
def handler?(handler_id)
38+
synchronize { @handlers.key? handler_id }
3939
end
4040

41-
# @return copy of the hooks
42-
def hooks
43-
synchronize { @hooks }.clone
41+
# @return copy of the handlers
42+
def handlers
43+
synchronize { @handlers }.clone
4444
end
4545

46-
# install `Kernel#at_exit` callback to execute added hooks
46+
# install `Kernel#at_exit` callback to execute added handlers
4747
def install
4848
synchronize do
4949
@installed ||= begin
@@ -64,18 +64,18 @@ def enabled=(value)
6464
synchronize { @enabled = value }
6565
end
6666

67-
# run the hooks manually
68-
# @return ids of the hooks
67+
# run the handlers manually
68+
# @return ids of the handlers
6969
def run
70-
hooks, _ = synchronize { hooks, @hooks = @hooks, {} }
71-
hooks.each do |_, hook|
70+
handlers, _ = synchronize { handlers, @handlers = @handlers, {} }
71+
handlers.each do |_, handler|
7272
begin
73-
hook.call
73+
handler.call
7474
rescue => error
7575
log ERROR, error
7676
end
7777
end
78-
hooks.keys
78+
handlers.keys
7979
end
8080

8181
private

0 commit comments

Comments
 (0)