future.rb 0.0.1 → 1.0.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -5
- data/lib/future.rb +12 -1
- data/test/test_future.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e68ad7ab93da7d2a53a223e9a25d46e4df90555b
|
4
|
+
data.tar.gz: 86155d69157ffffef291691ab35bf343a23ab89d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45a20dbce8cace0f95277dbe4a8f8da37d61836e50c92ee6c356d28a940022196c90ea1cf9e7d8f7204b22296617d78aafcb809736c3650f962525793a1dd66e
|
7
|
+
data.tar.gz: 4698e5d09be81ca75d61ca49b73349beee66d96cf32442ae990f5e26630522699b19a5d1a0caa9c2e6b79bef93721255d31696d8b2548112a11fa3cb57805bc5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# future.rb 
|
1
|
+
# future.rb [](http://badge.fury.io/rb/future.rb) 
|
2
2
|
|
3
3
|
A simple concurrent [futures](https://en.wikipedia.org/wiki/Futures_and_promises) library for Ruby.
|
4
4
|
|
@@ -13,15 +13,15 @@ def fetch_url(url)
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def crawl_urls(urls)
|
16
|
-
Future.all(urls.map {
|
16
|
+
Future.all(urls.map { |url|
|
17
17
|
fetch_url(url)
|
18
18
|
})
|
19
19
|
end
|
20
20
|
|
21
21
|
results = crawl_urls([
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"
|
22
|
+
"https://google.com/",
|
23
|
+
"https://twitter.com/",
|
24
|
+
"https://github.com/",
|
25
25
|
]).value
|
26
26
|
```
|
27
27
|
|
data/lib/future.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
class Future < Thread
|
2
|
-
VERSION = "0.0
|
2
|
+
VERSION = "1.0.0"
|
3
3
|
|
4
4
|
def self.all(futures)
|
5
5
|
Future { futures.map(&:value) }
|
6
6
|
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
case status
|
10
|
+
when nil
|
11
|
+
"#<#{self.class} (errored)>"
|
12
|
+
when false
|
13
|
+
"#<#{self.class} value=#{value}>"
|
14
|
+
else
|
15
|
+
"#<#{self.class} (incomplete)>"
|
16
|
+
end
|
17
|
+
end
|
7
18
|
end
|
8
19
|
|
9
20
|
def Future(&bk)
|
data/test/test_future.rb
CHANGED
@@ -17,4 +17,21 @@ class TestFuture < MiniTest::Test
|
|
17
17
|
Future { 789 },
|
18
18
|
]).value
|
19
19
|
end
|
20
|
+
|
21
|
+
def test_to_s_running
|
22
|
+
fut = Future { sleep }
|
23
|
+
assert_equal "#<Future (incomplete)>", fut.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_to_s_complete
|
27
|
+
fut = Future { 123 }
|
28
|
+
fut.value
|
29
|
+
assert_equal "#<Future value=123>", fut.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_to_s_errored
|
33
|
+
fut = Future { raise }
|
34
|
+
fut.value rescue nil
|
35
|
+
assert_equal "#<Future (errored)>", fut.to_s
|
36
|
+
end
|
20
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: future.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Somerville
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple concurrent futures library for Ruby with the goal of making
|
14
14
|
concurrent/asynchronous programming easier.
|