Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Does not "When" call completed method in "Subscribe" ? #57

Closed
hotmiyacchi opened this issue Apr 7, 2015 · 2 comments
Closed

Does not "When" call completed method in "Subscribe" ? #57

hotmiyacchi opened this issue Apr 7, 2015 · 2 comments

Comments

@hotmiyacchi
Copy link

Hi there,
I'm quite impressed to use UniRx and trying things these days.

Let me ask a question that I couldn't get "complete" at this code.
Observable.EveryUpdate()
.Where(x => x < 10)
.Subscribe(x => Debug.Log(x),
ex => Debug.LogError(ex.Message),
() => Debug.Log("completed"));

Does not "When" call completed method in "Subscribe" ?

@neuecc
Copy link
Owner

neuecc commented Apr 7, 2015

Observable.EveryUpdate is an infinite sequence generator and Where is only filter.
For example, if sequence returns 10 or less again, Where throughout the value again.

// 0,1,2,3,4,5,6,7,8,9,-10,-11,-12,-13,....,
Observable.EveryUpdate()
    .Select(x => (x >= 10) ? -x : x)
    .Where(x => x < 10);

If you want to stop sequence, you can use Observable.TakeWhile.

Observable.EveryUpdate()
    .TakeWhile(x => x < 10)
    .Subscribe(x => Debug.Log(x), ex => Debug.LogError(ex.Message), () => Debug.Log("completed"));

See: Intro to Rx's Reducing a sequence section.
http://www.introtorx.com/content/v1.0.10621.0/05_Filtering.html

@hotmiyacchi
Copy link
Author

Thanks a lot for your perfect response!

I really appreciate for your work.

@neuecc neuecc closed this as completed Apr 9, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants