What actually happens when using async/await inside a LINQ statement?

I recommend that you not think of this as “using async within LINQ”. Keep in mind what’s in-between the two: delegates. Several LINQ operators take delegates, and async can be used to create an asynchronous delegate. So, when you have an asynchronous method BazAsync that returns a Task: Task BazAsync(TBar bar); then this code results … Read more

Are there any benefits of reading each field async from a SqlDataReader?

After some peeking at reflector, the interesting methods here (GetFieldValueAsync<T>, IsDBNullAsync, and the internal method GetBytesAsync) only do “interesting” code for the CommandBehavior.SequentialAccess scenario. So: if you’re not using that: don’t bother – the row data is already buffered in memory, and Task<T> is pure overhead (although it will at least be an already-completed task … Read more

How do I make a function asynchronous in C++?

This can be done portably with modern C++ or even with old C++ and some boost. Both boost and C++11 include sophisticated facilities to obtain asynchronous values from threads, but if all you want is a callback, just launch a thread and call it. 1998 C++/boost approach: #include <iostream> #include <string> #include <boost/thread.hpp> void callback(const … Read more

Can I run a JS script from another using `fetch`?

Fetch API is supposed to provide promise-based API to fetch remote data. Loading random remote script is not AJAX – even if jQuery.ajax is capable of that. It won’t be handled by Fetch API. Script can be appended dynamically and wrapped with a promise: const scriptPromise = new Promise((resolve, reject) => { const script = … Read more

In the VS Code “Debug Console”, run a JavaScript await function

VS Code Debug Console supports top level async/await (https://github.com/microsoft/vscode-js-debug#top-level-await) however the issue might be you’re paused on the breakpoint. if you use await while paused on a breakpoint, you’ll only get a pending Promise back. This is because the JavaScript event loop is paused while on a breakpoint.

What is the ValueTask equivalent of Task.CompletedTask?

All structs have a default constructor. The default constructor of ValueTask creates a completed ValueTask: var completedValueTask = new ValueTask(); Or alternatively: ValueTask completedValueTask = default; Update: The official documentation has been updated with the following note: An instance created with the parameterless constructor or by the default(ValueTask) syntax (a zero-initialized structure) represents a synchronously, … Read more