-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from fedeAlterio/async-computed
Added AsyncComputed and AsyncEffect Added support for cancellation Created a factory interface for computed signals in order to centralize cancellation and exceptions dotnet/reactive replaced by R3
- Loading branch information
Showing
52 changed files
with
2,139 additions
and
506 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: .NET | ||
|
||
on: | ||
push: | ||
branches: [ "*" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 6.0.x | ||
- name: Restore dependencies | ||
run: dotnet restore ./SignalsDotnet | ||
- name: Build | ||
run: dotnet build -c Release ./SignalsDotnet --no-restore | ||
- name: Test | ||
run: dotnet test -c Release ./SignalsDotnet/SignalsDotnet.Tests --no-build --verbosity normal | ||
- name: Benchmarks | ||
run: | | ||
dotnet build -c Release ./SignalsDotnet/SignalsDotnet.PeformanceTests/ | ||
dotnet run -c Release --project ./SignalsDotnet/SignalsDotnet.PeformanceTests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Release to NuGet | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 6.0.x | ||
- name: Restore dependencies | ||
run: dotnet restore ./SignalsDotnet | ||
- name: Build | ||
run: dotnet build -c Release ./SignalsDotnet --no-restore | ||
- name: Test | ||
run: dotnet test -c Release ./SignalsDotnet/SignalsDotnet.Tests --no-build --verbosity normal | ||
- name: Pack nugets | ||
run: dotnet pack SignalsDotnet/SignalsDotnet -c Release --no-build --output . | ||
- name: Push to NuGet | ||
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.nuget_api_key}} --source https://api.nuget.org/v3/index.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
SignalsDotnet/SignalsDotnet.PeformanceTests/MainThreadAwaitableExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace SignalsDotnet.Tests.Helpers; | ||
|
||
public static class MainThreadAwaitableExtensions | ||
{ | ||
public static MainThreadAwaitable SwitchToMainThread(this object _) => new(); | ||
} | ||
|
||
/// <summary> | ||
/// If awaited, force the continuation to run on a Single-threaded synchronization context. | ||
/// That's the exact behavior of Wpf Synchronization Context (DispatcherSynchronizationContext) | ||
/// So basically: | ||
/// 1) after the await we switch thread. | ||
/// 2) Every other continuation will run on the same thread as it happens in Wpf. | ||
/// </summary> | ||
public readonly struct MainThreadAwaitable : INotifyCompletion | ||
{ | ||
public MainThreadAwaitable GetAwaiter() => this; | ||
public bool IsCompleted => SynchronizationContext.Current == TestSingleThreadSynchronizationContext.Instance; | ||
public void OnCompleted(Action action) => TestSingleThreadSynchronizationContext.Instance.Post(_ => action(), null); | ||
public void GetResult() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Running; | ||
using BenchmarkDotNet.Toolchains.InProcess.NoEmit; | ||
using R3; | ||
using SignalsDotnet; | ||
using SignalsDotnet.Tests.Helpers; | ||
|
||
BenchmarkRunner.Run<ComputedBenchmarks>(); | ||
|
||
public class BenchmarkConfig : ManualConfig | ||
{ | ||
public BenchmarkConfig() | ||
{ | ||
AddJob(Job.MediumRun | ||
.WithToolchain(InProcessNoEmitToolchain.Instance)); | ||
} | ||
} | ||
|
||
[MemoryDiagnoser] | ||
[Config(typeof(BenchmarkConfig))] | ||
public class ComputedBenchmarks | ||
{ | ||
readonly Signal<int> _signal = new(0); | ||
readonly IAsyncReadOnlySignal<int> _asyncComputed; | ||
readonly IReadOnlySignal<int> _computed; | ||
|
||
public ComputedBenchmarks() | ||
{ | ||
_computed = Signal.Computed(() => _signal.Value, x => x with{SubscribeWeakly = false}); | ||
_asyncComputed = Signal.AsyncComputed(async _ => | ||
{ | ||
var x = _signal.Value; | ||
await Task.Yield(); | ||
return x; | ||
}, -1); | ||
} | ||
|
||
[Benchmark] | ||
public int ComputedRoundTrip() | ||
{ | ||
_ = _computed.Value; | ||
_signal.Value = 0; | ||
_signal.Value = 1; | ||
return _computed.Value; | ||
} | ||
|
||
[Benchmark] | ||
public async ValueTask<int> AsyncComputedRoundTrip() | ||
{ | ||
await this.SwitchToMainThread(); | ||
|
||
_ = _asyncComputed.Value; | ||
_signal.Value = 0; | ||
_signal.Value = 1; | ||
return await _asyncComputed.Values | ||
.FirstAsync(x => x == 1) | ||
.ConfigureAwait(ConfigureAwaitOptions.ForceYielding); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
SignalsDotnet/SignalsDotnet.PeformanceTests/SignalsDotnet.PeformanceTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SignalsDotnet\SignalsDotnet.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.