Skip to content

Commit

Permalink
Housekeeping Add SDk 7 (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Nov 5, 2023
1 parent c8806fd commit 1ce4e98
Show file tree
Hide file tree
Showing 10 changed files with 706 additions and 723 deletions.
11 changes: 7 additions & 4 deletions src/Directory.build.props
Expand Up @@ -7,6 +7,7 @@
<Owners>xpaulbettsx;ghuntley</Owners>
<NoWarn>$(NoWarn);VSX1000</NoWarn>
<Platform>AnyCPU</Platform>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Description>Make sure your asynchronous operations show up to work on time</Description>
<PackageReleaseNotes>https://github.com/reactiveui/punchclock/releases</PackageReleaseNotes>
<RepositoryUrl>https://github.com/reactiveui/punchclock</RepositoryUrl>
Expand All @@ -25,6 +26,7 @@

<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="$(IsTestProject)">
Expand All @@ -33,13 +35,13 @@

<ItemGroup Condition="$(IsTestProject)">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.console" Version="2.5.2" />
<PackageReference Include="xunit" Version="2.6.0" />
<PackageReference Include="xunit.runner.console" Version="2.6.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Include="Xunit.StaFact" Version="1.1.11" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="DiffEngine" Version="12.3.0" />
<PackageReference Include="DiffEngine" Version="12.4.1" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -53,6 +55,7 @@

<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\LICENSE" Pack="true" PackagePath="LICENSE" />
<None Include="$(MSBuildThisFileDirectory)..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
Expand All @@ -61,7 +64,7 @@

<ItemGroup>
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.507" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.6.0" PrivateAssets="All" />
<PackageReference Include="Roslynator.Analyzers" Version="4.6.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Punchclock.sln
Expand Up @@ -12,7 +12,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Items", "Items", "{E035091F
analyzers.tests.ruleset = analyzers.tests.ruleset
Directory.build.props = Directory.build.props
global.json = global.json
..\README.md = ..\README.md
stylecop.json = stylecop.json
..\version.json = ..\version.json
EndProjectSection
EndProject
Global
Expand Down
82 changes: 38 additions & 44 deletions src/Punchclock/KeyedOperation.cs
Expand Up @@ -4,72 +4,66 @@
// See the LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;

namespace Punchclock
namespace Punchclock;

internal abstract class KeyedOperation : IComparable<KeyedOperation>
{
internal abstract class KeyedOperation : IComparable<KeyedOperation>
{
public bool CancelledEarly { get; set; }
public bool CancelledEarly { get; set; }

public int Priority { get; set; }
public int Priority { get; set; }

public int Id { get; set; }
public int Id { get; set; }

public string? Key { get; set; }
public string? Key { get; set; }

public IObservable<Unit>? CancelSignal { get; set; }
public IObservable<Unit>? CancelSignal { get; set; }

public bool KeyIsDefault => string.IsNullOrEmpty(Key) || Key == OperationQueue.DefaultKey;
public bool KeyIsDefault => string.IsNullOrEmpty(Key) || Key == OperationQueue.DefaultKey;

public abstract IObservable<Unit> EvaluateFunc();
public abstract IObservable<Unit> EvaluateFunc();

public int CompareTo(KeyedOperation other)
public int CompareTo(KeyedOperation other)
{
// NB: Non-keyed operations always come before keyed operations in
// order to make sure that serialized keyed operations don't take
// up concurrency slots
if (KeyIsDefault != other.KeyIsDefault)
{
// NB: Non-keyed operations always come before keyed operations in
// order to make sure that serialized keyed operations don't take
// up concurrency slots
if (KeyIsDefault != other.KeyIsDefault)
{
return KeyIsDefault ? 1 : -1;
}

return other.Priority.CompareTo(Priority);
return KeyIsDefault ? 1 : -1;
}

return other.Priority.CompareTo(Priority);
}
}

[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Generic implementation of same class name.")]
internal class KeyedOperation<T> : KeyedOperation
{
public Func<IObservable<T>>? Func { get; set; }
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Generic implementation of same class name.")]
internal class KeyedOperation<T> : KeyedOperation
{
public Func<IObservable<T>>? Func { get; set; }

public ReplaySubject<T> Result { get; } = new ReplaySubject<T>();
public ReplaySubject<T> Result { get; } = new ReplaySubject<T>();

public override IObservable<Unit> EvaluateFunc()
public override IObservable<Unit> EvaluateFunc()
{
if (Func == null)
{
if (Func == null)
{
return Observable.Empty<Unit>();
}
return Observable.Empty<Unit>();
}

if (CancelledEarly)
{
return Observable.Empty<Unit>();
}
if (CancelledEarly)
{
return Observable.Empty<Unit>();
}

var signal = CancelSignal ?? Observable.Empty<Unit>();
var ret = Func().TakeUntil(signal).Multicast(Result);
ret.Connect();
var signal = CancelSignal ?? Observable.Empty<Unit>();
var ret = Func().TakeUntil(signal).Multicast(Result);
ret.Connect();

return ret.Select(_ => Unit.Default);
}
return ret.Select(_ => Unit.Default);
}
}

0 comments on commit 1ce4e98

Please sign in to comment.