diff options
author | Steve Kemp <steve@steve.org.uk> | 2015-02-18 10:25:16 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2015-02-18 10:25:16 +0000 |
commit | ce041875b331c6cd4d308e7da550f5aca265c53e (patch) | |
tree | 3b62358a96f48201e00a2f5e1f4340928cf0ee23 | |
parent | 017830edfabf028d60143b52f80971ceaaa41c1f (diff) |
Prefer "while true" to "while 1"
Also only sleep between fetches if we couldn't find a job because
the queue was empty.
-rw-r--r-- | lib/custodian/queue.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb index 1ef9c61..1bdbee2 100644 --- a/lib/custodian/queue.rb +++ b/lib/custodian/queue.rb @@ -94,12 +94,16 @@ end def fetch(timeout = 1) job = nil - while( 1 ) + while( true ) foo, job = @redis.blpop( "queue", :timeout => timeout ) - return job if ( job ) - sleep( timeout ) + if ( job ) + return job + else + sleep( timeout ) + end + end end |