Home RxJS: invoke two async calls, return the first that passes a condition, or a special value of none of them does
Reply: 0

RxJS: invoke two async calls, return the first that passes a condition, or a special value of none of them does

user4927
1#
user4927 Published in September 21, 2018, 8:10 am

Using RxJS, I want to invoke two different asynchronous operations, which may or may not return null. They may also take indefinite time to complete.

I want to achieve the following:

  • If operation A returns value 1, then immediately return value 1
  • If operation B returns value 2, then immediately return value 2
  • If both operation A and B return null, then return null.

I suppose I can achieve the first two simply as follows:

const bothOperations = merge(callA(), callB());
const firstSuccess = bothOperations.first(res => res !== null);
return firstSuccess;

But how do I get the third possibility into this?

share|improve this question

1 Answer 1

active oldest votes
up vote 5 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306191 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO