Cysharp / R3

The new future of dotnet/reactive and UniRx.
MIT License
1.71k stars 70 forks source link

Observable.Interval not returning int - Unity #198

Closed guidodelphora closed 2 months ago

guidodelphora commented 2 months ago

In UniRx we could do something like this which would give us the time of the interval

Observable.Interval(TimeSpan.FromSeconds(1))
                .Subscribe(time => Debug.Log("Time: " + time));

I'm doing exactly the same with R3 and the Interval returns a Unit, is this the expected behaviour?

Thanks !

neuecc commented 2 months ago

You can use Interval().Index().

guidodelphora commented 2 months ago

Ok great thanks ! It works but now I see a problem with the Timer. Maybe I'm wrong and I can't check right away how I did it with UniRx, but with this code I would expect to have a 5 seconds timer, with an OnNext every 1 second. But what is happening is that the 5 is a delay, and then it starts printing every 1 second.

       Observable.Timer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(1))
                .Index()
                .Subscribe(number => Debug.Log("timer" + number) );
neuecc commented 2 months ago

Timer should behave the same as UniRx, the first argument is the delay until the first time, the second argument is the delay for subsequent iterations. If you want to make the whole process last 5 seconds, you can combine Interval and Take(TimeSpan).

guidodelphora commented 2 months ago

Oh okok. So probably I had an extension method for doing this, of UniRx, because in my previous company we did this in a different way.

So yeah thanks and sorry for the misunderstanding