RamblingCookieMonster / PSRabbitMq

PowerShell module to send and receive messages from a RabbitMq server
http://ramblingcookiemonster.github.io/RabbitMQ-Intro/
MIT License
47 stars 29 forks source link

Wait-rabbitmqMessage Timeout question/issue #6

Closed gaelcolas closed 8 years ago

gaelcolas commented 8 years ago

Hi,

I haven't tested this yet, but it looks like the While loop is only decreasing a counter [int], without pausing in that loop. Also the $Timeout variable has a default value of 1, so $SecondsRemaining = [Double]::PositiveInfinity is never reached/used.

I would prefer a loop with a timespan like this: https://mjolinor.wordpress.com/2012/01/14/making-a-timed-loop-in-powershell/

But ensuring backward compatibility with an [int] as param requires a bit extra work and I don't have time atm.

So just filing for later.

gpduck commented 8 years ago

The pause is in the dequeue command on line 151. The first parameter is a wait time.

When $Timeout is explicitly set to 0 the statement will evaluate to false and SecondsRemaining will be set to PositiveInfinity. This is done instead of using -1 (or the overload with no timeout) so that the wait thread doesn't block the script forever and you can still use CTRL+C to cancel the wait. That being said, we should probably update this to allow a 0 to pass through and generate an immediate error if there is no message and test for negative numbers to represent infinite waits.

As far as the TimeSpan goes, I also prefer it but didn't really feel like cluttering up the code when adding .TotalSeconds isn't really that much more work in the function call.

gaelcolas commented 8 years ago

It's much clearer after a coffee.

Sorry for that, and thanks for your reply :)