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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 062317c445eef79ce86d7ce5c8fbc2bfdd732c64
4
- data.tar.gz: 596430e75506e3bf582244c2ca688b8fdc424846
3
+ metadata.gz: e68ad7ab93da7d2a53a223e9a25d46e4df90555b
4
+ data.tar.gz: 86155d69157ffffef291691ab35bf343a23ab89d
5
5
  SHA512:
6
- metadata.gz: a4e35cf81995eb26961b3c44efcc1215539ee3a40f9c216105b75b94361c2497e98d576bf127f82a54e973fcda858fc81c51fadb65326dd777cfed20078ebdef
7
- data.tar.gz: bf6cb1786651ff67e663ee83d3a14e1c778def0bbde4f9b1aa799476dc328bbfb42eaa87d940265b07f2ba76b0cb7470068c682c6079e26a2aefec8390ab4c0f
6
+ metadata.gz: 45a20dbce8cace0f95277dbe4a8f8da37d61836e50c92ee6c356d28a940022196c90ea1cf9e7d8f7204b22296617d78aafcb809736c3650f962525793a1dd66e
7
+ data.tar.gz: 4698e5d09be81ca75d61ca49b73349beee66d96cf32442ae990f5e26630522699b19a5d1a0caa9c2e6b79bef93721255d31696d8b2548112a11fa3cb57805bc5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- future.rb (0.0.1)
4
+ future.rb (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # future.rb ![](https://api.travis-ci.org/charliesome/future.rb.svg)
1
+ # future.rb [![](https://badge.fury.io/rb/future.rb.svg)](http://badge.fury.io/rb/future.rb) ![](https://api.travis-ci.org/charliesome/future.rb.svg)
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
- "http://google.com/",
23
- "http://twitter.com/",
24
- "http://github.com/",
22
+ "https://google.com/",
23
+ "https://twitter.com/",
24
+ "https://github.com/",
25
25
  ]).value
26
26
  ```
27
27
 
@@ -1,9 +1,20 @@
1
1
  class Future < Thread
2
- VERSION = "0.0.1"
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)
@@ -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.1
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-04-21 00:00:00.000000000 Z
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.