I\'m using TypeScript with the MongoDB node.js driver. Note, this is not a Mongo question, its just the particular use case of this issue I\'m having.
Pretty much ev
I was wrong, this doesn't work in C# either. Here's the example of the same code from TypeScript, written in C#, that does not work:
using System.IO;
using System;
using System.Threading.Tasks;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World!");
var task = Wrapper(cb => FakeMongoFunctionWithCallback(5, cb));
}
static void FakeMongoFunctionWithCallback(int arg, Action callback)
{
// just pass through the arg into the callback, pretending we went to a db and came back with that result
callback(null, arg);
}
static Task Wrapper(Action> action) {
var tcs = new TaskCompletionSource();
action((err, res) => {
if (err != null) tcs.SetException(err);
else tcs.SetResult(res);
});
return tcs.Task;
}
}