Skip to content

Instantly share code, notes, and snippets.

@to11mtm
to11mtm / SingleThreadedScheduler.cs
Created November 13, 2022 23:20 — forked from davidfowl/SingleThreadedScheduler.cs
A sample showing how to schedule work on a single thread
using System.Collections.Concurrent;
using System.Threading.Channels;
var channel = Channel.CreateUnbounded<int>();
var syncContext = new SingleThreadedSyncContext();
syncContext.Post(async _ =>
{
await foreach (var item in channel.Reader.ReadAllAsync())
@to11mtm
to11mtm / EventLoopThreadScheduler.cs
Created February 1, 2022 22:50 — forked from noseratio/EventLoopThreadScheduler.cs
Single thread event loop scheduler, based on Rx EventLoopScheduler but with added SynchronizationContext and TPL TaskScheduler API
namespace Noseratio;
/// <summary>
/// Single thread event loop scheduler, based on Rx <seealso cref="EventLoopScheduler"/>
/// but with added SynchronizationContext and TPL TaskScheduler API
/// https://gist.github.com/noseratio/22a291e1d69f6d1cea547623ad9c9147
/// </summary>
public sealed partial class EventLoopThreadScheduler :
TaskScheduler,
IScheduler,
@to11mtm
to11mtm / BigDecimal.cs
Created February 26, 2021 21:09 — forked from JcBernack/BigDecimal.cs
BigDecimal
using System;
using System.Numerics;
namespace Common
{
/// <summary>
/// Arbitrary precision decimal.
/// All operations are exact, except for division. Division never determines more digits than the given precision.
/// Source: https://gist.github.com/JcBernack/0b4eef59ca97ee931a2f45542b9ff06d
/// Based on https://stackoverflow.com/a/4524254