.net - Http polling until request is fulfilled with Rx -


i requesting resource on http restful api. resource takes time reach 'complete' status , responding http status code reflects completeness of resource.

the calling client user waiting consume resource not want wait indefinitely. therefore api polled maximum number of attempts 'complete' resource. should api return status indicating resource complete, resource returned stack consumption. if api not return status indicating resource complete within maximum number of attempts client should stop polling , return kind of failure status.

in order achieve @ moment using thread.sleep(500) block thread waiting result. causing me nightmares thinking how inefficient is, looking improve technique.

i have looked rx , trying in vain bend observable.interval() having trouble trying observe on calling thread. ideally know code should like! at:

 observable.interval(timespan.frommilliseconds(500))            .observeon(synchronizationcontext.current)            .take(10)            .subscribe(i =>                {                   // check if resource complete                }); 

observable.fromasync(token => restsharpclient.executetaskasync(request, token))     .selectmany(response =>         response.data.hascompleted             ? observable.return(response)             : observable.throwexception(new exception("resource not ready."))                 .delaysubscription(timespan.fromseconds(5))         )     .retry(10); 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -