Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subscribe as last method raised

Is there a way to subscribe a method though it would be called last when the onNext is raised?

m_subject.Subscribe(() => Console.writeLine("firstSubscription");
m_subject.SubscribeLast(() => Console.writeLine("secondSubscription");
m_subject.Subscribe(() => Console.writeLine("thirdSubscription");

m_subject.OnNext();

// prints:
// firstSubscription
// thirdSubscription
// secondSubscription
like image 651
ie1 Avatar asked May 22 '26 22:05

ie1


1 Answers

You cannot have a subscriber be executed last, but you can wrap all your calls in a single subscription.

Something like that:

Action action = () => {};
Action lastAction = () => {};

m_subject.Subscribe(() => 
{
    action();
    lastAction();
});

action += (() => Console.writeLine("firstSubscription");
lastAction += (() => Console.writeLine("secondSubscription");
action += (() => Console.writeLine("thirdSubscription");

m_subject.OnNext();

// prints:
// firstSubscription
// thirdSubscription
// secondSubscription
like image 99
Falanwe Avatar answered May 24 '26 12:05

Falanwe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!