rest-core 3.5.7 → 3.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92e289bb3e825b93385443dade7adf26959b90b8
4
- data.tar.gz: 5861deec728b6d154f582702c5b2643ad7797b07
3
+ metadata.gz: 23c11f1f962e09fd0bbb320ca71d7f74618dd79a
4
+ data.tar.gz: c9a39501f38e887d9a8ce115bd3280ac4151d253
5
5
  SHA512:
6
- metadata.gz: 6a33744abd434667196c62f2066c0fecfa0315d0d397239964d16d13d7726cd94d0aa98dc3581924e84912decbb6f32040106d42cdeaafd5b962d3ba75382c94
7
- data.tar.gz: d6f3fe16efe1d82931cbb88cd9053509e2ca064e7d693365d963c5aefe154ef04e8e08d154aa3b79c4f4f3035e3795c6e14022d526a03a9624cdeff84e5e06c1
6
+ metadata.gz: 889495dc4261d1ae0dea20a0d821e5320053083c12c830508a17574dbf8a42fd1413ed5a7d83f3f396ed70c04df050b143e8c48f9f2d6e76982f1ac79382ffa1
7
+ data.tar.gz: e90f5213c0a9a4e0517b5ced5bf970c31793334c4224e47ab684c4a9ed29f06bb29699f55743dd7d689d8e22838a48e567b291cbcbfc7d6bed7299f0b6bdbd70
data/.travis.yml CHANGED
@@ -1,11 +1,19 @@
1
-
1
+ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.0
5
5
  - 2.1
6
6
  - 2.2
7
- - rbx-2
8
- - jruby
7
+ - rbx
8
+ - jruby-9
9
9
 
10
+ before_install:
11
+ - rvm get head
12
+ - rvm reload
13
+ - rvm use --install $TRAVIS_RUBY_VERSION --binary --latest
10
14
  install: 'bundle install --retry=3'
11
- script: 'ruby -r bundler/setup -S rake test'
15
+ script: 'ruby -vr bundler/setup -S rake test'
16
+
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: rbx
data/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGES
2
2
 
3
+ ## rest-core 3.5.8 -- 2015-12-07
4
+
5
+ ### Enhancements
6
+
7
+ * Added `Client.defer` for doing arbitrary asynchronous tasks.
8
+
3
9
  ## rest-core 3.5.7 -- 2015-09-10
4
10
 
5
11
  ### Incompatible changes
data/README.md CHANGED
@@ -246,6 +246,22 @@ end
246
246
 
247
247
  If you're using unicorn, you probably want to put that in the config.
248
248
 
249
+ ### Random Asynchronous Tasks
250
+
251
+ Occasionally we might want to do some asynchronous tasks which could take
252
+ the advantage of the concurrency facilities inside rest-core, for example,
253
+ using `wait` and `shutdown`. You could do this with `defer` for a particular
254
+ client. Still take `RC::Universal` as an example:
255
+
256
+ ``` ruby
257
+ RC::Universal.defer do
258
+ sleep(1)
259
+ puts "Slow task done"
260
+ end
261
+
262
+ RC::Universal.wait
263
+ ```
264
+
249
265
  ### Persistent connections (keep-alive connections)
250
266
 
251
267
  Since we're using [httpclient][] by default now, we would reuse connections,
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'thread'
3
+ require 'weakref'
3
4
  require 'rest-core/client'
4
5
 
5
6
  class RestCore::Builder
@@ -104,6 +105,20 @@ class RestCore::Builder
104
105
 
105
106
  def thread_pool; RestCore::ThreadPool[self]; end
106
107
 
108
+ def defer
109
+ raise ArgumentError.new('no block given') unless block_given?
110
+ promise = RestCore::Promise.new(RestCore::CLIENT => self)
111
+ give_promise(WeakRef.new(promise))
112
+ promise.defer do
113
+ begin
114
+ yield
115
+ ensure
116
+ promise.done
117
+ end
118
+ end
119
+ promise
120
+ end
121
+
107
122
  def give_promise weak_promise, ps=promises, m=mutex
108
123
  m.synchronize do
109
124
  ps << weak_promise
@@ -211,7 +211,7 @@ module RestCore::Client
211
211
  private
212
212
  def request_complete res
213
213
  if err = res[FAIL].find{ |f| f.kind_of?(Exception) }
214
- RC::Promise.set_backtrace(err) unless err.backtrace
214
+ Promise.set_backtrace(err) unless err.backtrace
215
215
  error_callback.call(err) if error_callback
216
216
  if res[ASYNC]
217
217
  res.merge(response_key(res) => err)
@@ -118,6 +118,11 @@ class RestCore::Promise
118
118
  self
119
119
  end
120
120
 
121
+ # called in Client.defer to mark this promise as done
122
+ def done
123
+ fulfill('', 0, {})
124
+ end
125
+
121
126
  # It's considered done only if the HTTP request is done, and we're not
122
127
  # in asynchronous mode otherwise the callback should be called first.
123
128
  # For synchronous mode, since we're waiting for the callback anyway,
@@ -1,4 +1,4 @@
1
1
 
2
2
  module RestCore
3
- VERSION = '3.5.7'
3
+ VERSION = '3.5.8'
4
4
  end
data/rest-core.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rest-core 3.5.7 ruby lib
2
+ # stub: rest-core 3.5.8 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rest-core"
6
- s.version = "3.5.7"
6
+ s.version = "3.5.8"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Lin Jen-Shin (godfat)"]
11
- s.date = "2015-09-10"
11
+ s.date = "2015-12-07"
12
12
  s.description = "Modular Ruby clients interface for REST APIs.\n\nThere has been an explosion in the number of REST APIs available today.\nTo address the need for a way to access these APIs easily and elegantly,\nwe have developed rest-core, which consists of composable middleware\nthat allows you to build a REST client for any REST API. Or in the case of\ncommon APIs such as Facebook, Github, and Twitter, you can simply use the\ndedicated clients provided by [rest-more][].\n\n[rest-more]: https://github.com/godfat/rest-more"
13
13
  s.email = ["godfat (XD) godfat.org"]
14
14
  s.files = [
@@ -113,7 +113,7 @@ Gem::Specification.new do |s|
113
113
  "test/test_universal.rb"]
114
114
  s.homepage = "https://github.com/godfat/rest-core"
115
115
  s.licenses = ["Apache License 2.0"]
116
- s.rubygems_version = "2.4.8"
116
+ s.rubygems_version = "2.5.0"
117
117
  s.summary = "Modular Ruby clients interface for REST APIs."
118
118
  s.test_files = [
119
119
  "test/test_auth_basic.rb",
data/test/test_promise.rb CHANGED
@@ -45,6 +45,18 @@ describe RC::Promise do
45
45
  @promise.send(:headers).should.eq('K' => 'V')
46
46
  end
47
47
 
48
+ would 'work, wait, done' do
49
+ @client.pool_size = 3
50
+ flag = 0
51
+ promise = @client.defer do
52
+ flag.should.eq 0
53
+ flag += 1
54
+ end
55
+ @client.wait
56
+ flag.should.eq 1
57
+ promise.should.done?
58
+ end
59
+
48
60
  would 'warn on callback error' do
49
61
  mock(any_instance_of(RC::Promise)).warn(is_a(String)) do |msg|
50
62
  msg.should.eq 'boom'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.7
4
+ version: 3.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  version: '0'
189
189
  requirements: []
190
190
  rubyforge_project:
191
- rubygems_version: 2.4.8
191
+ rubygems_version: 2.5.0
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: Modular Ruby clients interface for REST APIs.