From ce041875b331c6cd4d308e7da550f5aca265c53e Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Wed, 18 Feb 2015 10:25:16 +0000 Subject: Prefer "while true" to "while 1" Also only sleep between fetches if we couldn't find a job because the queue was empty. --- lib/custodian/queue.rb | 10 +++++++--- 1 file 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 -- cgit v1.2.1