Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
ssteiner #1
Member since Jan 2016 · 26 posts · Location: Switzerland
Group memberships: Members
Show profile · Link to this post
Subject: Timeout in PubSubManager
This is a simple one: does timeout = 0 do the same as calling the operation without that parameter?
Avatar
Alex #2
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
no, it would pass the value 0 to the TPL
Avatar
ssteiner #3
Member since Jan 2016 · 26 posts · Location: Switzerland
Group memberships: Members
Show profile · Link to this post
In reply to post #1
And is there a way to use one line of code for both scenarios (with and without timeout) or do I have to build a switch?

Also.. what's the unit? milliseconds, seconds? I think it is not seconds because if I use the value 1, every now and then I do get a timeout.
Avatar
Alex #4
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by ssteiner:
And is there a way to use one line of code for both scenarios (with and without timeout) or do I have to build a switch?

just use a timeout value which is high, or create your own extension method.

IQs require always a response. And usually the response should be generated pretty fast.
I would not suggest very high timeout values. Your code and the underlying Task in MatriX would wait forever otherwise.

MatriX does something like this internal for the methods you refer to:

  1. await Task.WhenAny(resultCompletionSource.Task, Task.Delay(timeout)))

And there are still the methods which raise a callback to you.

Quote by ssteiner:
Also.. what's the unit? milliseconds, seconds? I think it is not seconds because if I use the value 1, every now and then I do get a timeout.

the unit is milliseconds. We added a task to update the Xml docs for the next release.
Avatar
ssteiner #5
Member since Jan 2016 · 26 posts · Location: Switzerland
Group memberships: Members
Show profile · Link to this post
Thanks. I do not plan high timeouts.. but high depends on whether it is seconds or milliseconds.
I'm aiming for that server switchover scenario... if the xmpp channel is still open, I want to terminate everything properly.. but if I hit the sweet spot (xmpp still up when I decide I must terminate subscriptions.. but going down when I attempt to terminate them), I need a timeout so as not to wait forever for operations that are going to fail.
Avatar
Alex #6
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
OK, I see your use case.

In this case the result it probably also not that important. When you sent the packet the server has to take of terminating the subscription. It does not matter if you wait for the success result or note.

  • You could use the non Async methods and don't care about the callcack.
  • You can use the async once with a timeout of something like 5 seconds
  • If for some reason your server is lagging or overloaded with requests you could use a lower timeout like 1s to not delay your shutdown code.
Avatar
ssteiner #7
Member since Jan 2016 · 26 posts · Location: Switzerland
Group memberships: Members
Show profile · Link to this post
5 seconds is in fact the value I used (or rather 5000ms) :)
And since I don't care about the result, I just start the task and don't await it.. combining highest speed, async processing and being a good citizen :)
Avatar
Alex #8
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Great to hear that is works as expected.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS