fraggle 0.1.0 → 0.1.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/README.md +40 -30
- metadata +2 -2
data/README.md
CHANGED
@@ -12,47 +12,57 @@
|
|
12
12
|
require 'fraggle'
|
13
13
|
|
14
14
|
EM.start do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
e.cas # => "123"
|
21
|
-
end
|
22
|
-
end
|
15
|
+
# Fraggle keeps track of this addr plus all others it finds once
|
16
|
+
# connected. In the event of a lost connection, fraggle will attempt
|
17
|
+
# other doozers until one accepts or it runs out of options; An
|
18
|
+
# AssemlyError will be raised if that later happens.
|
19
|
+
c = Fraggle.connect "127.0.0.1:8046"
|
23
20
|
|
24
21
|
c.get "/foo" do |e|
|
25
|
-
if
|
26
|
-
e.
|
27
|
-
e.cas
|
28
|
-
e.dir?
|
22
|
+
if e.ok?
|
23
|
+
e.value # => "bar"
|
24
|
+
e.cas # => "123"
|
25
|
+
e.dir? # => false
|
26
|
+
e.notdir? # => true
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
30
|
watch = c.watch "/foo" do |e|
|
33
31
|
# The event has:
|
34
32
|
# ------------------------
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
33
|
+
e.err_code # => nil
|
34
|
+
e.err_detail # => nil
|
35
|
+
e.path # => "/foo"
|
36
|
+
e.value # => "bar"
|
37
|
+
e.cas # => "123"
|
38
|
+
e.dir? # => false
|
39
|
+
e.notdir? # => true
|
40
|
+
e.set? # => true
|
41
|
+
e.del? # => false
|
42
|
+
|
43
|
+
done_something_with(e)
|
44
|
+
|
45
|
+
# Phoney check for example
|
46
|
+
if can_stop_watching?(path)
|
47
|
+
c.cancel(watch)
|
48
|
+
end
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
## Setting a key (this will trigger the watch above)
|
52
|
+
c.set "/foo", "zomg!", :missing do |e|
|
53
|
+
case true
|
54
|
+
when e.mismatch? # CAS mis-match
|
55
|
+
# retry if we must
|
56
|
+
c.set "/foo", "zomg!", e.cas do |e|
|
57
|
+
if ! e.ok?
|
58
|
+
# we give up
|
59
|
+
end
|
53
60
|
end
|
61
|
+
when e.ok?
|
62
|
+
e.cas # => "123"
|
63
|
+
else
|
64
|
+
raise e.err_detail
|
54
65
|
end
|
55
|
-
|
56
66
|
end
|
57
67
|
|
58
68
|
end
|