pry-em 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/pry-em.rb +25 -5
- metadata +3 -3
data/lib/pry-em.rb
CHANGED
@@ -2,7 +2,7 @@ EmCommands = Pry::CommandSet.new do
|
|
2
2
|
|
3
3
|
create_command /\s*em\s*([0-9\.]*)\s*:(.*)/ do
|
4
4
|
|
5
|
-
description "
|
5
|
+
description "Run code in eventmachine and wait for any Deferrable results."
|
6
6
|
options(
|
7
7
|
:keep_retval => true,
|
8
8
|
:interpolate => false,
|
@@ -10,6 +10,22 @@ EmCommands = Pry::CommandSet.new do
|
|
10
10
|
:requires_gem => 'eventmachine'
|
11
11
|
)
|
12
12
|
|
13
|
+
banner <<-BANNER
|
14
|
+
The em: command runs your code in an event machine context.
|
15
|
+
|
16
|
+
If your code returns a deferrable, it wil wait for that deferrable to succeed
|
17
|
+
or fail before returning you to Pry.
|
18
|
+
|
19
|
+
By default the em: command will wait forever for your deferrable to return
|
20
|
+
a result, if you'd like to wait for a shorter length of time, you can add
|
21
|
+
a timeout (in seconds) before the colon in em:.
|
22
|
+
|
23
|
+
e.g.
|
24
|
+
pry(main)> em 3: EM::HttpRequest.new("http://www.google.com").get
|
25
|
+
RuntimeError: Timeout after 3.0 seconds
|
26
|
+
|
27
|
+
BANNER
|
28
|
+
|
13
29
|
def process(timeout, source)
|
14
30
|
# We store the retval and the em-state in globals so that we can catch exceptions
|
15
31
|
# raised in the event loop and pass them back pretending to the user that the
|
@@ -34,7 +50,7 @@ EmCommands = Pry::CommandSet.new do
|
|
34
50
|
deferrable = target.eval(source)
|
35
51
|
|
36
52
|
# TODO: Allow the user to configure the default timeout
|
37
|
-
timeout = timeout == "" ?
|
53
|
+
timeout = timeout == "" ? nil : Float(timeout)
|
38
54
|
|
39
55
|
wait_for_deferrable(deferrable, timeout) unless deferrable.nil?
|
40
56
|
end
|
@@ -89,7 +105,9 @@ EmCommands = Pry::CommandSet.new do
|
|
89
105
|
#
|
90
106
|
def wait_for_deferrable(deferrable, timeout)
|
91
107
|
|
92
|
-
|
108
|
+
if timeout
|
109
|
+
EM::Timer.new(timeout) { @@em_state = :timeout if waiting? }
|
110
|
+
end
|
93
111
|
|
94
112
|
[:callback, :errback].each do |method|
|
95
113
|
begin
|
@@ -98,7 +116,8 @@ EmCommands = Pry::CommandSet.new do
|
|
98
116
|
@@retval = result.size > 1 ? result : result.first
|
99
117
|
end
|
100
118
|
rescue NoMethodError
|
101
|
-
|
119
|
+
@@retval = deferrable
|
120
|
+
@@em_state = :callback
|
102
121
|
break
|
103
122
|
end
|
104
123
|
end
|
@@ -111,7 +130,8 @@ EmCommands = Pry::CommandSet.new do
|
|
111
130
|
raise @@retval if @@em_state != :callback && Exception === @@retval
|
112
131
|
|
113
132
|
# TODO: This doesn't interact well with the pager.
|
114
|
-
output.print "#{@@em_state} "
|
133
|
+
output.print "#{@@em_state} " if @@em_state != :callback
|
134
|
+
|
115
135
|
@@retval
|
116
136
|
|
117
137
|
# If the main thread is interrupted we must ensure that the @@em_state
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-em
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Conrad Irwin
|