Using async/await for multiple tasks

I’m using an API client that is completely asynchrounous, that is, each operation either returns Task or Task<T>, e.g: static async Task DoSomething(int siteId, int postId, IBlogClient client) { await client.DeletePost(siteId, postId); // call API client Console.WriteLine(“Deleted post {0}.”, siteId); } Using the C# 5 async/await operators, what is the correct/most efficient way to start … Read more

If my interface must return Task what is the best way to have a no-operation implementation?

In the code below, due to the interface, the class LazyBar must return a task from its method (and for argument’s sake can’t be changed). If LazyBars implementation is unusual in that it happens to run quickly and synchronously – what is the best way to return a No-Operation task from the method? I have … Read more

Combination of async function + await + setTimeout

I am trying to use the new async features and I hope solving my problem will help others in the future. This is my code which is working: async function asyncGenerator() { // other code while (goOn) { // other code var fileList = await listFiles(nextPageToken); var parents = await requestParents(fileList); // other code } … Read more

How can I wait In Node.js (JavaScript)? l need to pause for a period of time

I’m developing a console script for personal needs. I need to be able to pause for an extended amount of time, but, from my research, Node.js has no way to stop as required. It’s getting hard to read users’ information after a period of time… I’ve seen some code out there, but I believe they … Read more

Best practice to call ConfigureAwait for all server-side code

When you have server-side code (i.e. some ApiController) and your functions are asynchronous – so they return Task<SomeObject> – is it considered best practice that any time you await functions that you call ConfigureAwait(false)? I had read that it is more performant since it doesn’t have to switch thread contexts back to the original thread … Read more

How would I run an async Task method synchronously?

I am learning about async/await, and ran into a situation where I need to call an async method synchronously. How can I do that? Async method: public async Task<Customers> GetCustomers() { return await Service.GetCustomersAsync(); } Normal usage: public async void GetCustomers() { customerList = await GetCustomers(); } I’ve tried using the following: Task<Customer> task = … Read more

Using async/await with a forEach loop

Are there any issues with using async/await in a forEach loop? I’m trying to loop through an array of files and await on the contents of each file. import fs from ‘fs-promise’ async function printFiles () { const files = await getFilePaths() // Assume this works fine files.forEach(async (file) => { const contents = await … Read more