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

Awaiting to a filtered ReactiveProperty #517

Open
kordian-kowalski opened this issue Jul 14, 2022 · 1 comment
Open

Awaiting to a filtered ReactiveProperty #517

kordian-kowalski opened this issue Jul 14, 2022 · 1 comment

Comments

@kordian-kowalski
Copy link

kordian-kowalski commented Jul 14, 2022

In my game I have a ReactiveProperty<Vector3Int> pickedCell that is written to when a cell on a grid is clicked on by the player.

Awaiting it directly works as I would expect:

var cell = await pickedCell;
Debug.Log(cell); // Works!

However if I filter the events in any way - even a dummy one like here:

var cell = await pickedCell.Where(c => true);
Debug.Log(cell); // Never executes

The value is never returned.

Am I doing something wrong here?

To be clear - I'm using UniTask, but I reproduced this with a clean project with just UniRx installed.

@kordian-kowalski
Copy link
Author

kordian-kowalski commented Jul 14, 2022

I think I figured it out:
LINQ-like functions, including Where return an IObservable which when awaited, by default returns after the observable stream is completed (the value being the last value in the stream)

For anyone interested, you can do things like:

await someReactiveProperty.Where(...).Skip(1).First();

or

await someReactiveProperty.SkipLatestValueOnSubscribe().Where(...).First();

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

1 participant