Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ReactiveUI.Uno] WebAssembly RxApp.TaskpoolScheduler should return WasmScheduler #1

Open
HavenDV opened this issue Jun 18, 2021 · 10 comments
Labels
bug Something isn't working now

Comments

@HavenDV
Copy link

HavenDV commented Jun 18, 2021

Currently, multithreading is not supported in WebAssembly.
When developing for Uno, at the moment I have to explicitly override TaskPoolScheduler so that the code works on all platforms.

@HavenDV HavenDV added the bug Something isn't working label Jun 18, 2021
@jeromelaban
Copy link

@HavenDV what would you want this property to do? What's your workaround, with an example?

@HavenDV
Copy link
Author

HavenDV commented Aug 3, 2021

At the moment, I am using the solution via DI:

_ = services
    // WebAssembly does not support Threads for .Net5/.Net6 now.
    .AddSingleton(static provider =>
    {
        return provider.GetRequiredService<Platform>() switch
        {
            Platform.WebAssembly => RxApp.MainThreadScheduler,
            _ => RxApp.TaskpoolScheduler,
        };
    })

and explicitly get and pass taskPoolScheduler in code.
Platform is explicitly specified in Shared code through #ifdef instructions.

I see the solution through detecting the WebAssembly platform at a platform agnostic level (Inside the main ReactiveUI package targeting .Net Standard 2.0) and returning the correct TaskPoolScheduler (RxApp.MainThreadScheduler) for the WebAssembly platform.
The main difficulty is in detecting WebAssembly.

@glennawatson
Copy link
Contributor

glennawatson commented Aug 3, 2021

are you using ReactiveUI.Uno nuget package, It's meant to go the WasmScheduler if it's netstandard2.0

https://github.com/reactiveui/Reactive.Wasm/blob/master/src/System.Reactive.Wasm/Internal/WasmScheduler.cs

GitHub
A Web Assembly versions of the System.Reactive classes. - Reactive.Wasm/WasmScheduler.cs at master · reactiveui/Reactive.Wasm

@HavenDV
Copy link
Author

HavenDV commented Aug 3, 2021

If I understand everything correctly, should I use this package at the platform level? Which causes the same difficulties, because our Core package with all ViewModels (and the code that uses specific Scheduler) targets the same as the main ReactiveUI package

@glennawatson
Copy link
Contributor

Just your views project, based on having ReactiveUI.Uno it'll run the registration in that project and should set it to a WasmScheduler.

@HavenDV
Copy link
Author

HavenDV commented Aug 3, 2021

From my point of view, the ReactiveUI.Uno package should do this on its own.

Or there must be some documentation about it because I didn't notice anything about it until I heard from you.

@glennawatson
Copy link
Contributor

Yeah that's what it should do, if it's not its a bug.

What is TaskPoolScheduler by default before you do your override?

@HavenDV
Copy link
Author

HavenDV commented Aug 3, 2021

I'm trying to find out. I still haven't figured out how to use Debugger with a WASM project.

@HavenDV
Copy link
Author

HavenDV commented Aug 3, 2021

I added this to the App constructor of the Uno application:

        public App()
        {
            Console.WriteLine(RxApp.TaskpoolScheduler);
#if __WASM__
            PlatformEnlightenmentProvider.Current.EnableWasm();
#endif
            Console.WriteLine(RxApp.TaskpoolScheduler);
            Console.WriteLine(System.Reactive.Concurrency.WasmScheduler.Default);

image

@glennawatson
Copy link
Contributor

Ok yeah, this will have to be fixed then.

I'll see if we can get a point release next release.

@HavenDV HavenDV changed the title [ReactiveUI.Uno] WebAssembly RxApp.TaskpoolScheduler should return RxApp.MainThreadScheduler [ReactiveUI.Uno] WebAssembly RxApp.TaskpoolScheduler should return WasmScheduler Aug 3, 2021
@glennawatson glennawatson transferred this issue from reactiveui/ReactiveUI Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working now
Projects
None yet
Development

No branches or pull requests

3 participants