-
Rx Hands-on-Lab (HOL) for C# aka "Curing the asynchronous blues with the Reactive Extensions for .NET (C#)" repo
-
RX Intro by Lee Campbell (and his excellent free e-book, repo)
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
// md wfapp | |
// dotnet new winforms | |
// then copy/paste this | |
using System.Diagnostics; | |
namespace wfapp; | |
public partial class Form1 : Form | |
{ |
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
// https://twitter.com/noseratio/status/1597159958734217217 | |
using System.Diagnostics; | |
namespace wfapp; | |
public partial class Form1 : Form | |
{ | |
// library code | |
private static async Task LibApiAsync(Func<Task> waitForEvent) |
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
// A helper SynchronizationContext to debug deadlocks by @noseratio | |
// If you install DebugSyncContext at the very beginning of your console app and run it under debugger, | |
// it should stop where the deadlock is happening, with a better access to the stack frame. | |
using System.Diagnostics; | |
SynchronizationContext.SetSynchronizationContext(new DebugSyncContext()); | |
Console.WriteLine("Hello!"); |
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
public sealed class AsyncQueue<T>: IAsyncDisposable | |
{ | |
private readonly Queue<T> _queue = new(); | |
private readonly SemaphoreSlim _semaphore = new(initialCount: 1, maxCount: 1); | |
private readonly CancellationTokenSource _cts = new(); | |
private TaskCompletionSource _itemTcs = new(TaskCreationOptions.RunContinuationsAsynchronously); | |
public async ValueTask<(bool, T)> TryPeekAsync(CancellationToken cancelToken) | |
{ | |
await _semaphore.WaitAsync(cancelToken); |
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
// https://twitter.com/noseratio/status/1535173151910350848 | |
// https://docs.microsoft.com/en-us/dotnet/core/extensions/generic-host | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
using var host = Host.CreateDefaultBuilder(Environment.GetCommandLineArgs()) | |
.ConfigureLogging( | |
logging => |
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
// by Theodor Zoulias | |
// https://stackoverflow.com/questions/72558093/in-rx-net-how-do-i-make-a-subject-to-resemble-taskcompletionsource-behavior/72561100?noredirect=1#comment128188846_72561100 | |
// | |
// comment out "#define USING_LAZY" | |
#define USING_LAZY | |
using System; | |
using System.Reactive.Linq; | |
using System.Reactive.Subjects; | |
using System.Reactive.Threading.Tasks; |
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
// https://stackoverflow.com/q/72471152/1768303 | |
// https://dotnetfiddle.net/bLYDgw | |
/* | |
I don't think I should be seeing "Emitting: 19" after "Cancelling" | |
Emitting: 18 | |
TakeUntil passed: 18 | |
OnNext: 18 | |
Cancelling |
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
// https://twitter.com/noseratio/status/1526314613364490241 | |
public sealed class AsyncQueue<T>: IAsyncDisposable | |
{ | |
private readonly Queue<T> _queue = new(); | |
private readonly SemaphoreSlim _semaphore = new(initialCount: 1); | |
private readonly CancellationTokenSource _cts = new(); | |
private TaskCompletionSource<DBNull> _itemTcs = new(TaskCreationOptions.RunContinuationsAsynchronously); | |
public async Task Clear(CancellationToken cancelToken) |
Full credits to @eviltester's original post.
Steps:
-
Goto https://twitter.com/settings/your_twitter_data/twitter_interests
-
Block https://twitter.com/i/api/1.1/account/personalization/p13n_preferences.json in F12 Network Tools
-
Execute in F12 Console (copy/paste):
NewerOlder