Closed epsmae closed 3 years ago
This works:
.Select(employee => Observable.FromAsync(() => LoadActivity(employee)))
.Merge()
@dsuryd No this only flickers the dashboard once and results in an empty dashboard --> "Uncaught TypeError: Cannot read property 'map' of null" as mentioned above.
It's throwing that error because the initial value of RecentActivity
is null because the async data is formulated after the fact. So you need to set the initial value to non-null, something like below:
RecentActivity = Observable
.Interval(TimeSpan.FromSeconds(2))
.StartWith(0)
.Select(_ => GetRandomEmployee(employeeService))
.Select(employee => Observable.FromAsync(() => LoadActivity(employee)))
.Merge()
.StartWith(new[] { new Activity() });
@dsuryd thanks for your answer. This displays an empty activity for the start, not really what I desire.
One workaround would be to check in the client code if the objetc is "valid". Is there another way achieve this without changing the client code?
Updating the client code to ignore null/empty value is a trivial solution. Otherwise, make it synchronous only when populating the initial value.
@dsuryd
.StartWith(new[] { LoadInitialActivity.Result });
Is blocking the UI so I will go with:
.Select(employee => Observable.FromAsync(() => LoadActivity(employee)))
And check for null in the client.
Thanks alot.
Question:
What is the correct way to use async observable?
Used async sample
I simplified your sample like the following
Now I want to use an async method, I tried the following approaches without success.
Attempt 1:
Attempt 2:
The following errors occur:
The following works but is not the desired way
As a reference just an async method: