async-await

Task.Yield() in library needs ConfigureWait(false)

橙三吉。 提交于 2019-12-21 07:25:44
问题 It's recommended that one use ConfigureAwait(false) whenever when you can, especially in libraries because it can help avoid deadlocks and improve performance. I have written a library that makes heavy use of async (accesses web services for a DB). The users of the library were getting a deadlock and after much painful debugging and tinkering I tracked it down to the single use of await Task.Yield() . Everywhere else that I have an await, I use .ConfigureAwait(false) , however that is not

How to cancel NetworkStream.ReadAsync without closing stream

偶尔善良 提交于 2019-12-21 07:25:29
问题 I am trying to use NetworkStream.ReadAsync() to read data but I cannot find how to cancel the ReadAsync() once called. For background, the NetworkStream is provided to me by a connected BluetoothClient object (from 32Feet.NET Bluetooth Library). The current get-it-working code I'm trying is below. int bytesRead; while (this.continueReading) { bytesRead = await this.stream.ReadAsync(this.buffer, 0, (int)this.buffer.Length); Console.WriteLine("Received {0} bytes", bytesRead); } Console

How to await inside RxJS subscribe method

拈花ヽ惹草 提交于 2019-12-21 07:22:28
问题 Inside of an RxJS subject's subscribe callback, I want to await on an async function. Below is a code example which the typescript transpiler complains about saying: Error:(131, 21) TS2304:Cannot find name 'await'. async ngOnInit() { this.subscriber = dateSubscription.subscribe((date: Date) => { let dbKey = await this._someService.saveToDatabase(someObject); // wait for db write to finish before evaluating the next code // ... some other code here }); } Usually I see this when trying to call

How to await inside RxJS subscribe method

守給你的承諾、 提交于 2019-12-21 07:22:19
问题 Inside of an RxJS subject's subscribe callback, I want to await on an async function. Below is a code example which the typescript transpiler complains about saying: Error:(131, 21) TS2304:Cannot find name 'await'. async ngOnInit() { this.subscriber = dateSubscription.subscribe((date: Date) => { let dbKey = await this._someService.saveToDatabase(someObject); // wait for db write to finish before evaluating the next code // ... some other code here }); } Usually I see this when trying to call

How to await inside RxJS subscribe method

╄→гoц情女王★ 提交于 2019-12-21 07:22:06
问题 Inside of an RxJS subject's subscribe callback, I want to await on an async function. Below is a code example which the typescript transpiler complains about saying: Error:(131, 21) TS2304:Cannot find name 'await'. async ngOnInit() { this.subscriber = dateSubscription.subscribe((date: Date) => { let dbKey = await this._someService.saveToDatabase(someObject); // wait for db write to finish before evaluating the next code // ... some other code here }); } Usually I see this when trying to call

Why compiler does not allow using await inside catch block

泄露秘密 提交于 2019-12-21 07:12:18
问题 Let say I have an async method: public async Task Do() { await Task.Delay(1000); } Another method is trying to call Do method inside catch block public async Task DoMore() { try { } catch (Exception) { await Do(); //compiled error. } } But this way, the compiler does not allow using await inside catch , is there any reason behind the scene why we could not use it that way? 回答1: Update This will be supported in C# 6. It turned out that it wasn't fundamentally impossible, and the team worked

How do I kick off an entity stored procedure in EF6 async and not wait for a return?

安稳与你 提交于 2019-12-21 07:11:59
问题 I'd like to just punt a call over to the SQL Server and not wait for a return. I have an imported Entity Function from a Stored Procedure that I'd like to call asynchronously this way in Entity Framework 6.0.0-rc1. Is this possible? What's the syntax? Entity Function: RecalculateBudgetNumbers(int id) 回答1: Start a new Task that creates a fresh data context and invokes that function. Just don't wait/await that task. Let it run by itself to completion. Make sure to log errors. Don't swallow

“Async All the Way Down”: Well, what's all the way at the bottom? [closed]

痴心易碎 提交于 2019-12-21 07:09:02
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago . I'm trying to fully understand async - await and one of the gaps in my understanding is seeing what is "All the Way Down." I create an async method, it is called by another async method, etc., all the way down to something that I understand in vague terms like "a UI" or "a web server that can

INSERT operation using Node.js and PostgreSQL doesn't work

蹲街弑〆低调 提交于 2019-12-21 07:08:11
问题 I'm creating my first app using Node.js and PostgreSQL. This app connect to db, create table, do web scraping of a web site, insert info to db and then disconnect from db. I'm trying to do using async/await . The problem is that the insert operation doesn't work. There is no errors, simply table coverages remains empty. This is my code. app.js : const postgreSQLlib = require('./middlewares/postgreSQLlib.js') const scraper = require('./routers/scraper.js'); const start = async function() {

Async Try(blah) pattern [duplicate]

耗尽温柔 提交于 2019-12-21 06:56:20
问题 This question already has answers here : How to write a async method with out parameter? (11 answers) Closed 4 months ago . I'm looking for recommendations on how to handle the following situation. I'm creating methods for trying to get at some data, following this pattern: // Typical pattern public bool TryBlah(string key, out object value) { // ... set value and return boolean } I've run into an issue when trying to follow this pattern on they async versions because you cannot use out on