Reputation: 199
This is the code in my UserService:
var request = new MvxRestRequest("http://localhost:8080/user/auth");
var client = Mvx.Resolve<IMvxRestClient>();
MvxStreamRestResponse response = await client.MakeStreamRequestAsync(request);
messageService.showMessage(response.StatusCode.ToString()); //Never reached when my server is down
When my REST is down, I never get the control again. How can I set a Timeout or another approach in this case?
Upvotes: 0
Views: 119
Reputation: 24470
MakeStreamRequestAsync
has an overload which takes a CancellationToken
:
Task<MvxStreamRestResponse> MakeStreamRequestAsync(MvxRestRequest restRequest, CancellationToken cancellationToken = default(CancellationToken));
You could use it with a CancellationTokenSource
and have that decide when to time out the request:
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
var response = await client.MakeStreamRequestAsync(request, cts.Token);
Upvotes: 3