Skip to content

Commit

Permalink
Merge pull request #1 from pfpack/feature/initial-create
Browse files Browse the repository at this point in the history
Feature/initial create
  • Loading branch information
andreise authored Sep 18, 2021
2 parents 888cbc4 + a03a97b commit 8f3730d
Show file tree
Hide file tree
Showing 62 changed files with 1,443 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: .NET

on:
push:
branches: [ feature/*, master ]

pull_request:
branches: [ master ]

release:
types: [ published ]
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
include-prerelease: true

- name: Create Local NuGet Directory
run: mkdir ~/nuget

- name: Add Local Nuget Source
run: dotnet nuget add source ~/nuget

- name: Restore AsyncPipeline
run: dotnet restore ./src/*/*/AsyncPipeline.csproj

- name: Build AsyncPipeline
run: dotnet build ./src/*/*/AsyncPipeline.csproj --no-restore -c Release

- name: Pack AsyncPipeline
run: dotnet pack ./src/*/*/AsyncPipeline.csproj --no-restore -o ~/nuget -c Release

- name: Push Packages
if: ${{ github.event_name == 'release' }}
run: dotnet nuget push "../../../nuget/*.nupkg" -s https://api.nuget.org/v3/index.json -k ${{ secrets.NuGetSourcePassword }} --skip-duplicate
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mono_crash.*
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
Expand Down Expand Up @@ -61,6 +62,9 @@ project.lock.json
project.fragment.lock.json
artifacts/

# ASP.NET Scaffolding
ScaffoldingReadMe.txt

# StyleCop
StyleCopReport.xml

Expand All @@ -86,6 +90,7 @@ StyleCopReport.xml
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
Expand Down Expand Up @@ -137,6 +142,11 @@ _TeamCity*
.axoCover/*
!.axoCover/settings.json

# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info

# Visual Studio code coverage results
*.coverage
*.coveragexml
Expand Down Expand Up @@ -196,6 +206,9 @@ PublishScripts/
*.nuget.props
*.nuget.targets

# Nuget personal access tokens and Credentials
nuget.config

# Microsoft Azure Build Output
csx/
*.build.csdef
Expand Down Expand Up @@ -348,3 +361,28 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd

# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp

# JetBrains Rider
.idea/
*.sln.iml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020-2021 Andrei Sergeev, Pavel Moskovoy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#nullable enable

using System.Threading;
using System.Threading.Tasks;

namespace System
{
public readonly partial struct AsyncPipeline<T> : IEquatable<AsyncPipeline<T>>
{
private static CancellationToken CanceledToken() => new(canceled: true);

private readonly ValueTask<T> valueTask;

private readonly bool isCanceled;

private readonly CancellationToken cancellationToken;

internal AsyncPipeline(ValueTask<T> valueTask, bool isCanceled, CancellationToken cancellationToken)
{
this.valueTask = valueTask;
this.isCanceled = isCanceled;
this.cancellationToken = cancellationToken;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#nullable enable

namespace System
{
partial struct AsyncPipeline<T>
{
public static bool operator ==(AsyncPipeline<T> left, AsyncPipeline<T> right)
=>
left.Equals(right);

public static bool operator !=(AsyncPipeline<T> left, AsyncPipeline<T> right)
=>
left.Equals(right) is false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#nullable enable

namespace System
{
partial struct AsyncPipeline<T>
{
public bool Equals(AsyncPipeline<T> other)
=>
ValueTaskComparer.Equals(valueTask, other.valueTask)
&& IsCanceledComparer.Equals(isCanceled, other.isCanceled)
&& CancellationTokenComparer.Equals(cancellationToken, other.cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#nullable enable

namespace System
{
partial struct AsyncPipeline<T>
{
public static bool Equals(AsyncPipeline<T> left, AsyncPipeline<T> right)
=>
left.Equals(right);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#nullable enable

using System.Diagnostics.CodeAnalysis;

namespace System
{
partial struct AsyncPipeline<T>
{
public override bool Equals([NotNullWhen(true)] object? obj)
=>
obj is AsyncPipeline<T> other
&& Equals(other);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#nullable enable

namespace System
{
partial struct AsyncPipeline<T>
{
public override int GetHashCode()
=>
HashCode.Combine(
EqualityContract,
ValueTaskComparer.GetHashCode(valueTask),
IsCanceledComparer.GetHashCode(isCanceled),
CancellationTokenComparer.GetHashCode(cancellationToken));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#nullable enable

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace System
{
partial struct AsyncPipeline<T>
{
private static Type EqualityContract => typeof(AsyncPipeline<T>);

private static IEqualityComparer<ValueTask<T>> ValueTaskComparer => EqualityComparer<ValueTask<T>>.Default;

private static IEqualityComparer<bool> IsCanceledComparer => EqualityComparer<bool>.Default;

private static IEqualityComparer<CancellationToken> CancellationTokenComparer => EqualityComparer<CancellationToken>.Default;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#nullable enable

using System.Threading;
using System.Threading.Tasks;

namespace System
{
partial struct AsyncPipeline<T>
{
public AsyncResultFlow<TSuccess, TFailure> Pipe<TSuccess, TFailure>(
Func<T, CancellationToken, Task<Result<TSuccess, TFailure>>> pipeAsync)
where TFailure : struct
=>
new(
InternalPipe(
pipeAsync ?? throw new ArgumentNullException(nameof(pipeAsync))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#nullable enable

namespace System
{
partial struct AsyncPipeline<T>
{
public AsyncResultFlow<TSuccess, TFailure> Pipe<TSuccess, TFailure>(Func<T, Result<TSuccess, TFailure>> pipe)
where TFailure : struct
=>
new(
InternalPipe(
pipe ?? throw new ArgumentNullException(nameof(pipe))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#nullable enable

using System.Threading;
using System.Threading.Tasks;

namespace System
{
partial struct AsyncPipeline<T>
{
public AsyncResultFlow<TSuccess, TFailure> PipeValue<TSuccess, TFailure>(
Func<T, CancellationToken, ValueTask<Result<TSuccess, TFailure>>> pipeAsync)
where TFailure : struct
=>
new(
InternalPipeValue(
pipeAsync ?? throw new ArgumentNullException(nameof(pipeAsync))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#nullable enable

using System.Threading;
using System.Threading.Tasks;

namespace System
{
partial struct AsyncPipeline<T>
{
public AsyncPipeline<TResult> Pipe<TResult>(Func<T, CancellationToken, Task<TResult>> pipeAsync)
=>
InternalPipe(
pipeAsync ?? throw new ArgumentNullException(nameof(pipeAsync)));

internal AsyncPipeline<TResult> InternalPipe<TResult>(Func<T, CancellationToken, Task<TResult>> pipeAsync)
=>
isCanceled || cancellationToken.IsCancellationRequested
? new(valueTask: default, isCanceled: true, cancellationToken: cancellationToken)
: new(valueTask: InnerPipeAsync(pipeAsync), isCanceled: false, cancellationToken: cancellationToken);

private async ValueTask<TResult> InnerPipeAsync<TResult>(Func<T, CancellationToken, Task<TResult>> pipeAsync)
{
var result = await valueTask.ConfigureAwait(false);
return await pipeAsync.Invoke(result, cancellationToken).ConfigureAwait(false);
}
}
}
26 changes: 26 additions & 0 deletions src/core-asyncpipeline/AsyncPipeline/AsyncPipeline.T/Pipe/Pipe.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#nullable enable

using System.Threading.Tasks;

namespace System
{
partial struct AsyncPipeline<T>
{
public AsyncPipeline<TResult> Pipe<TResult>(Func<T, TResult> pipe)
=>
InternalPipe(
pipe ?? throw new ArgumentNullException(nameof(pipe)));

internal AsyncPipeline<TResult> InternalPipe<TResult>(Func<T, TResult> pipe)
=>
isCanceled
? new(valueTask: default, isCanceled: true, cancellationToken: cancellationToken)
: new(valueTask: InnerPipeAsync(pipe), isCanceled: false, cancellationToken: cancellationToken);

private async ValueTask<TResult> InnerPipeAsync<TResult>(Func<T, TResult> pipe)
{
var result = await valueTask.ConfigureAwait(false);
return pipe.Invoke(result);
}
}
}
Loading

0 comments on commit 8f3730d

Please sign in to comment.