Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Don't subscribe when number of messages to receive is 0

Change-Id: I87a10f96a09dec7c9512fdd7b768a392e87a9633
  • Loading branch information...
commit 7d511a4ae7adc38d7cb8595d15d48a7f6bff79fb 1 parent bb1c43b
Pieter Noordhuis authored
15  cloud_controller/lib/nats_timed_request.rb
@@ -7,12 +7,17 @@ def timed_request(subject, data=nil, opts = {})
7 7
       timeout  = opts[:timeout]  || 1
8 8
       f = Fiber.current
9 9
       results = []
10  
-      sid = NATS.request(subject, data, :max => expected) do |msg|
11  
-        results << msg
12  
-        f.resume if results.length >= expected
  10
+
  11
+      # Subscribe when at least one message is expected to be received
  12
+      if expected > 0
  13
+        sid = NATS.request(subject, data, :max => expected) do |msg|
  14
+          results << msg
  15
+          f.resume if results.length >= expected
  16
+        end
  17
+        NATS.timeout(sid, timeout, :expected => expected) { f.resume }
  18
+        Fiber.yield
13 19
       end
14  
-      NATS.timeout(sid, timeout, :expected => expected) { f.resume }
15  
-      Fiber.yield
  20
+
16 21
       return results.slice(0, expected)
17 22
     end
18 23
   end

Git Notes

review

Code-Review+2: Patrick Bozeman <pbozeman@vmware.com>
Verified+1: CI Master <cf-ci@rbcon.com>
Submitted-by: Pieter Noordhuis <pnoordhuis@rbcon.com>
Submitted-at: Fri, 26 Oct 2012 22:40:25 +0000
Reviewed-on: http://reviews.cloudfoundry.org/10817
Project: cloud_controller
Branch: refs/heads/master

0 notes on commit 7d511a4

Please sign in to comment.
Something went wrong with that request. Please try again.