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

option to run dotnet on worker thread #94

Closed
wants to merge 22 commits into from
Closed

option to run dotnet on worker thread #94

wants to merge 22 commits into from

Conversation

elringus
Copy link
Owner

When using dotnet as application backend, it makes sense to run the process on a background thread to prevent stalling the main (UI) thread. Enabling CreateWorker build property will make dotnet run on worker thread and provide a mechanism to interact with the worker using the same APIs (via embedded comlink library):

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <CreateWorker>true</CreateWorker>
</PropertyGroup>

The dotnet web worker will start under the hood when the library is imported; the runtime can then be booted and used the same way. The only exception are the sync APIs: as it's not possible to communicate with web workers in blocking manner, all the methods will return promise, even if they do not return task on C# side.

When unit-testing applications with dotnet worker, define muteDotNetWorker global property to disable the worker creation on library import. Check the React sample on setting the variable with jest.

@elringus elringus added the enhancement New feature or enhancement label Oct 10, 2022
@codecov
Copy link

codecov bot commented Oct 10, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (9c16100) compared to base (260fd33).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##              main       #94    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           39        45     +6     
  Lines         1073      1193   +120     
  Branches       131       133     +2     
==========================================
+ Hits          1073      1193   +120     
Impacted Files Coverage Δ
DotNetJS/JavaScript/src/mono.ts 100.00% <0.00%> (ø)
DotNetJS/JavaScript/src/event.ts 100.00% <0.00%> (ø)
DotNetJS/JavaScript/test/boot.js 100.00% <0.00%> (ø)
DotNetJS/JavaScript/src/dotnet.ts 100.00% <0.00%> (ø)
DotNetJS/JavaScript/test/event.js 100.00% <0.00%> (ø)
DotNetJS/DotNet/Packer/PublishDotNetJS.cs 100.00% <0.00%> (ø)
DotNetJS/DotNet/Packer/Utilities/TextUtilities.cs 100.00% <0.00%> (ø)
.../DotNet/Packer/LibraryGenerator/LibraryTemplate.cs 100.00% <0.00%> (ø)
...DotNet/Packer/LibraryGenerator/LibraryGenerator.cs 100.00% <0.00%> (ø)
...acker/DeclarationGenerator/DeclarationGenerator.cs 100.00% <0.00%> (ø)
... and 8 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@elringus
Copy link
Owner Author

After some testing I've figured worker interaction layer adds too much complexity and makes debugging harder. It'll make more sense and will probably be more performant to use threading on C# side (#79).

@elringus elringus closed this Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant