Skip to content

Instantly share code, notes, and snippets.

View in-async's full-sized avatar

inasync in-async

View GitHub Profile
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace Commons {
public static class BlockingCollectionExtensions {
public static async Task<bool> WaitToReadAsync<T>(this BlockingCollection<T> source, CancellationToken cancellationToken) {
cancellationToken.ThrowIfCancellationRequested();
namespace System.Diagnostics.CodeAnalysis {
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
internal sealed class MaybeNullAttribute : Attribute {
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
internal sealed class AllowNullAttribute : Attribute {
}
}
using System;
namespace Commons {
/// <summary>
/// スレッド セーフなアキュムレータ。
/// </summary>
/// <typeparam name="T">アキュムレータが扱うデータ型。</typeparam>
public class ConcurrentAccumulator<T> {
private readonly object _lockObj = new object();
namespace Commons {
/// <summary>
/// https://github.com/dotnet/csharplang/issues/803#issuecomment-471575318
/// </summary>
public readonly struct ObjectIniter<T> {
public ObjectIniter(T obj) {
Obj = obj;
}
#nullable enable
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
namespace Inasync {
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace Inasync {
public static class BlockingCollectionExtensions {
public static void Post<TMessage>(this BlockingCollection<TMessage> channel, TMessage message) {
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace Inasync.Hosting {
public interface IRequestHandler {
@in-async
in-async / RemoveTrailingZerosConverter.cs
Created January 26, 2020 04:24
Remove decimal trailing zeros.
using System;
using Newtonsoft.Json;
namespace Commons {
public sealed class RemoveTrailingZerosConverter : JsonConverter {
public static readonly RemoveTrailingZerosConverter Default = new RemoveTrailingZerosConverter();
public override bool CanConvert(Type objectType) {
return objectType == typeof(decimal);
@in-async
in-async / CommandService.cs
Created January 17, 2020 09:40
CommandService inherited IHostedService
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Commons {
@in-async
in-async / CommandHostWithBackgroundService.cs
Last active January 23, 2022 16:20
Generic Host によるコマンド実装 (with BackgroundService)
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Inasync.Hosting {
public delegate Task CommandDelegate(string[] args, CancellationToken cancellationToken);