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
#nullable enable | |
using System; | |
namespace conapp | |
{ | |
/// <summary> | |
/// Resembling JavaScript's EventTarget | |
/// </summary> | |
public class EventTarget<T> where T : EventArgs | |
{ |
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
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace App | |
{ | |
class Program | |
{ | |
static async Task<int> Main() | |
{ |
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
void async function() { | |
// DeferredAsClass | |
class DeferredAsClass { | |
resolve; | |
reject; | |
promise = new Promise((s, f) => { this.resolve = s; this.reject = f; }); | |
} | |
// DeferredAsClassWithConstructor |
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
void async function() { | |
"use strict"; | |
// extending Promise | |
class PromiseEx extends Promise { | |
} | |
const iterations = 500_000; | |
const cached = Promise.resolve(); |
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
void async function() { | |
// extending Promise | |
class PromiseEx extends Promise { | |
} | |
// extending Promise as Deferred | |
class Deferred extends Promise { | |
resolve; | |
reject; |
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
void async function() { | |
function createDeferred() { | |
let resolve, reject; | |
const promise = new Promise((...args) => [resolve, reject] = args); | |
return Object.freeze({ | |
resolve, | |
reject, | |
promise, | |
then: promise.then.bind(promise) | |
}); |
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://www.nuget.org/packages/Microsoft.Net.Compilers.Toolset | |
md cs-repl | cd | |
nuget install Microsoft.Net.Compilers.Toolset | |
# run a CS script, a useful alternative to PowerShell itself | |
echo 'Console.WriteLine("hello");' > script.csx | |
. (gci -recurse csi.exe).FullName script.csx | |
# run in REPL mode |
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
using System; | |
using System.Threading.Tasks; | |
public class Program | |
{ | |
public async static Task Main() | |
{ | |
await Task.Delay(1000); | |
Console.WriteLine("Hello after a delay!"); | |
} |
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>net5.0-windows</TargetFramework> | |
<OutputType>Exe</OutputType> | |
<DisableWinExeOutputInference>true</DisableWinExeOutputInference> | |
<UseWinForms>true</UseWinForms> | |
<UsingMicrosoftNETSdkWeb>true</UsingMicrosoftNETSdkWeb> | |
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://dev.to/noseratio/await-inside-javascript-template-strings-3kbj | |
// | |
// save this as .mjs or as "node --input-type=module < file.js" | |
const delay = (ms, result) => new Promise(r => setTimeout(r, ms, result)); | |
const interpolated = `Hello, ${await delay(1000, "World!")} Is this sync or async?`; | |
console.log(interpolated) |