J. Lennon
J. Lennon

Reputation: 3361

Listening messages from event value or timeout with Rx

Consider the following scenario:

Listening messages from event or timeout with Rx

How can I deal with it? I thought to use with "Observable.Amb" (after the "A"), but would have to create a subscription in all time manually, and that could complicate in time to stop or release the resources.

Upvotes: 0

Views: 112

Answers (1)

Brandon
Brandon

Reputation: 39182

Amb is indeed a good option:

var bSignal = bSource.Select(b => true).Take(1);
var timeoutSignal = Observable.Timer(TimeSpan.FromSeconds(2)).Select(t => false);
var resultSignal = Observable.Amb(bSignal, timeoutSignal);
var result = aSource.Select(a => resultSignal).Switch();

Upvotes: 1

Related Questions