async-await

is the below code captures the exceptions from original, continuation and child tasks in TPL?

依然范特西╮ 提交于 2019-12-22 07:46:12
问题 I am using TPL and async/await to build async API on top of webclient for my applications. And few of the places (generally where I need to run bunch of async tasks and wait for all of them in the end), am following code snippet. I just want to make sure I get it correct as even though writing async code is relatively easy with TPL and async/await debugging/trouble shooting is still challenging (both interactive debugging and troubleshooting issues at customer site) - so want to get it right.

Why is Task<HttpResponseMessage> not awaitable in my project?

此生再无相见时 提交于 2019-12-22 06:59:56
问题 I have a project that is targeting the .NET 4 framework and I've created a method which updates data in a database. The method itself also uses a flag (runAsync) to determine whether it should run asynchronously or not. I'm getting an error that 'System.Threading.Tasks.Task< HttpResponseMessage > is not awaitable' but I am using this same code in another application and it works fine. What am I doing wrong, or what am I missing to get this to work? Here is the code: public static async Task

How to know if a task completed synchronously?

血红的双手。 提交于 2019-12-22 06:32:50
问题 I faintly remember there being a property that tells us whether a task executed synchronously but my memory fails me just now. Or may be there isn't and I am mixing up the IAsyncResult.CompletedSynchronously with this one? 回答1: Check this: Task.IAsyncResult.CompletedSynchronously Property It's description looks much like the answer: Gets an indication of whether the operation completed synchronously. In order to check the property value you will have to cast the Task into IAsyncResult because

Implement async/await in sort function of arrays javascript

喜夏-厌秋 提交于 2019-12-22 05:41:11
问题 I am trying to implement a sort method on protractor ElementArrayFinder . As known, all protractor methods return promises. So my sort method has a condition which depends on promises resolution. I am using a node plugin for async/await in order to make it compatible with node.js versions lower than 6. (Here the plugin: https://www.npmjs.com/package/asyncawait) Here my code, where this is the ArrayElementFinder : var asyncCompare = async(function(a, b) { let x = await (a.getText()); let y =

Implement async/await in sort function of arrays javascript

旧巷老猫 提交于 2019-12-22 05:41:04
问题 I am trying to implement a sort method on protractor ElementArrayFinder . As known, all protractor methods return promises. So my sort method has a condition which depends on promises resolution. I am using a node plugin for async/await in order to make it compatible with node.js versions lower than 6. (Here the plugin: https://www.npmjs.com/package/asyncawait) Here my code, where this is the ArrayElementFinder : var asyncCompare = async(function(a, b) { let x = await (a.getText()); let y =

How to handle partial success in a batch of Tasks?

戏子无情 提交于 2019-12-22 05:28:14
问题 I have 3 Tasks that should run in parallel. I need to await all 3 and then continue processing their results. So something like: var results = await Task.WhenAll(task1, task2, task3); return process(results); This works fine when all 3 tasks complete successfully. However, if one of them fails I get an exception that bubbles up all the way. This is not what I want. If any of these tasks throws an InvalidOperationException I can continue processing, I just need the process method to have

Correct way to use done() while testing asyc/await with mocha

↘锁芯ラ 提交于 2019-12-22 05:23:30
问题 I am practicing basic unit test cases with mocha and a bit confused HOW and WHEN to use done() handler. How to use done() ? Below is my sample code where I am not able to use done : it('Testing insertDocumentWithIndex', async (done) => { try{ var data = await db.insertDocumentWithIndex('inspections', { "inspectorId" : 1, "curStatus" : 1, "lastUpdatedTS" : 1535222623216, "entryTS" : 1535222623216, "venueTypeId" : 1, "location" : [ 45.5891279, -45.0446183 ] }) expect(data.result.n).to.equal(1);

What happens when you await a failed task

拟墨画扇 提交于 2019-12-22 05:22:17
问题 I have a theoretical question to you. What happens if I await the Result of a Task inside another task? I want to know if my current system will work afterwards. A task gets launched and does some stuff. At some point that task might need another one in order to process data which the current task is not able to process by itself. So I use await to ensure that the current task won't continue as long as he has not the result of the helper task. But what happens if the helper fails? Will the

async / await vs BeginRead, EndRead

廉价感情. 提交于 2019-12-22 05:14:40
问题 I don't quite 'get' async and await yet, and I'm looking for some clarification around a particular problem I'm about to solve. Basically, I need to write some code that'll handle a TCP connection. It'll essentially just receive data and process it until the connection is closed. I'd normally write this code using the NetworkStream BeginRead and EndRead pattern, but since the async / await pattern is much cleaner, I'm tempted to use that instead. However, since I admittedly don't fully

Task when all, connection is closing

亡梦爱人 提交于 2019-12-22 05:11:22
问题 I'm trying to execute multiple SqlDataReaders using Task.WhenAll. But when the tasks are awaited I get "System.InvalidOperationException: Invalid operation. The connection is closed". Creation of tasks: List<Task<SqlDataReader>> _listTasksDataReader = new List<Task<SqlDataReader>>(); _listTasksDataReader.Add(GetSqlDataReader1(10)); _listTasksDataReader.Add(GetSqlDataReader2(10)); SqlDataReader[] _dataReaders = await Task.WhenAll(_listTasksDataReader); My "SqlDataReader" methods: public Task