async-await

Cypress.io How to handle async code

一笑奈何 提交于 2019-12-20 01:14:05
问题 I'm in the middle of process of moving our old capybara tests to cypress.io as our application is going SPA way. In our case we have over 2000 tests covering a lot of features. So common pattern to test feature is to have an user with created and published offer. On the beginning I wrote case where cypress were going trough page and clicking everything. It worked but I saw that offer create + publish took almost 1,5 minute to finish. And sometimes we need multiple offers. So we have a test

__awaiter is not defined when using async/await in Typescript

荒凉一梦 提交于 2019-12-20 01:05:32
问题 I have the following code snippet in Typescript: nsp.on('connection', async function (socket) { await this.emitInitialPackage(nsp, currentLine, currentCell); } emitInitialPackage(nsp: any, name: string, cell: any) { return db.Line.find({ where: { name: name, CellId: cell } }).then(results => { nsp.emit('value', results); }).catch(err => console.log(err)); } However, when this is compiled (v2.2.1) and run, I get the following error: Uncaught ReferenceError: __awaiter is not defined What does

Doesn't await when using ForEachAsync with await inside Action

不问归期 提交于 2019-12-19 22:00:09
问题 The following should return "C", but it returns "B" using System.Data.Entity; //... var state = "A"; var qry = (from f in db.myTable select f); await qry.ForEachAsync(async (myRecord) => { await DoStuffAsync(myRecord); state = "B"; }); state = "C"; return state; It doesn't wait for DoStuffAsync to complete, state="C" runs through and then later state="B" executes (because inside it is still awaiting). 回答1: That's because the implementation of ForEachAsync doesn't await the delegated action

Code coverage for async methods

旧时模样 提交于 2019-12-19 16:54:43
问题 When I analyse code coverage in Visual Studio 2012, any of the await lines in async methods are showing as not covered even though they are obviously executing since my tests are passing. The code coverage report says that the uncovered method is MoveNext , which is not present in my code (perhaps it's compiler-generated). Is there a way to fix code coverage reporting for async methods? Note : I just ran coverage using NCover, and the coverage numbers make a lot more sense using that tool. As

C# async/await strange behavior in console app

萝らか妹 提交于 2019-12-19 16:33:49
问题 I built some async/await demo console app and get strange result. Code: class Program { public static void BeginLongIO(Action act) { Console.WriteLine("In BeginLongIO start... {0} {1}", (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond, Thread.CurrentThread.ManagedThreadId); Thread.Sleep(1000); act(); Console.WriteLine("In BeginLongIO end... \t{0} {1}", (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond, Thread.CurrentThread.ManagedThreadId); } public static Int32 EndLongIO

C# async/await strange behavior in console app

我们两清 提交于 2019-12-19 16:33:11
问题 I built some async/await demo console app and get strange result. Code: class Program { public static void BeginLongIO(Action act) { Console.WriteLine("In BeginLongIO start... {0} {1}", (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond, Thread.CurrentThread.ManagedThreadId); Thread.Sleep(1000); act(); Console.WriteLine("In BeginLongIO end... \t{0} {1}", (DateTime.Now.Ticks - ticks) / TimeSpan.TicksPerMillisecond, Thread.CurrentThread.ManagedThreadId); } public static Int32 EndLongIO

Timeout behaviour in HttpWebRequest.GetResponse() vs GetResponseAsync()

僤鯓⒐⒋嵵緔 提交于 2019-12-19 16:10:15
问题 When I try the following code: var request = (HttpWebRequest)HttpWebRequest.Create(url); request.Timeout = 3; // a small value var response = request.GetResponse(); Console.WriteLine(response.ContentLength); for a URL that I know it is going to take more than 3 millisecond to load (I put a Thread.Sleep(110000) in Application_BeginRequest ) it works fine and throws a WebException as expected. Problem is when I switch to async method: var response = request.GetResponseAsync().Result; or var

SQL CLR awaitable not getting executed

半世苍凉 提交于 2019-12-19 12:22:40
问题 It is my understanding that the awaitable completes the remaining part of the executing code when they return back from the wait. I am trying to get this to work in an sql clr, and this is not working as both awaited process and codes beneath it are not getting executed. In debug method, the control just returns after executing the await line. how can i make this work, as the requirement is for clr to be executed without blocking the main thread so that other work can continue well in the db.

How to convert Node.js async streaming callback into an async generator?

余生长醉 提交于 2019-12-19 11:31:30
问题 I have a function that streams data in batches via a callback. Each batch will await the callback function before fetching another batch and the entire function returns a promise that resolves when all batches are finished. (I'm using TypeScript annotations to help with readability) async function callbackStream(fn: (batch: Array<number>) => Promise<void>) {} How do I to turn this function into an async generator that yields one value at a time? async function* generatorStream():

How to convert Node.js async streaming callback into an async generator?

浪尽此生 提交于 2019-12-19 11:31:22
问题 I have a function that streams data in batches via a callback. Each batch will await the callback function before fetching another batch and the entire function returns a promise that resolves when all batches are finished. (I'm using TypeScript annotations to help with readability) async function callbackStream(fn: (batch: Array<number>) => Promise<void>) {} How do I to turn this function into an async generator that yields one value at a time? async function* generatorStream():