Created
June 14, 2024 20:38
-
-
Save ragavendra/b9eb3e7b97720ccf7c393f158363ea28 to your computer and use it in GitHub Desktop.
Callbacks in Csharp like CommonJS style
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 static void Main() | |
{ | |
ReadFile("", (err, data) => { | |
if(err != null) { | |
Console.WriteLine("Err"); | |
return; | |
} | |
Console.WriteLine("Data " + data); | |
}); | |
Console.WriteLine("Hello World"); | |
} | |
private static Task ReadFile(string path, Action<string, string> action) { | |
var no = new Random().Next(0, 100); | |
if (no % 2 == 0) | |
action(null, "completed"); | |
else | |
action("err", null); | |
return default; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment