async-await

Xamarin - Asynchronous data binding

99封情书 提交于 2020-03-25 13:42:19
问题 I have following code: Page with lots of images, that are loaded dynamically with the databinding: base.OnAppearing(); if (!loaded) { loaded = true; BindingContext = new GalleryViewModel(pCode, gCode, gUrl); } viewmodel: namespace GalShare.ViewModel { class GalleryViewModel { public string pCode { get; set; } public string gCode { get; set; } public string gUrl { get; set; } public ObservableCollection<picdata> Galleries { get; set; } public GalleryViewModel(string pCode, string gCode, string

How to type node-postgres async query functions in TypeScript?

吃可爱长大的小学妹 提交于 2020-03-25 12:33:25
问题 I am fairly new to TypeScript and started to convert my existing server from ES6 to TypeScript. I am a bit lost and trying to figure out how to declare types for async functions. Here's a stub from the ES6 code: // db.js import { Pool } from 'pg'; const pool = new Pool({ connectionString: 'process.env.DB_CONNECTION', }); export default { query(text, params) { return new Promise((resolve, reject) => { try { const result = pool.query(text, params); return resolve(result); } catch (error) {

How to delegate an async function with non-static parameter by a trait?

牧云@^-^@ 提交于 2020-03-23 07:55:08
问题 Like this code: use std::future::Future; use std::pin::Pin; trait A { fn handle<'a>(&'a self, data: &'a i32) -> Pin<Box<dyn 'a + Future<Output = ()>>>; } impl<'b, Fut> A for fn(&'b i32) -> Fut where Fut: 'b + Future<Output = ()>, { fn handle<'a>(&'a self, data: &'a i32) -> Pin<Box<dyn 'a + Future<Output = ()>>> { Box::pin(self(data)) } } how can I implement A for all async fn(&i32) ? 回答1: This code should works: use std::future::Future; use std::pin::Pin; trait A<'a> { fn handle(&'a self,

Errors and warnings using @functions block in Razor Pages

青春壹個敷衍的年華 提交于 2020-03-23 07:49:26
问题 Because the @helper directive is no longer supported in ASP.NET Core Razor Pages, I've been using the @functions directive instead. @functions { void RenderTask(Models.Task task) { <tr> <td class="@Model.CssClass"> <p class="compact"> <span class="font-weight-bold">@task.Title</span> @if (!string.IsNullOrWhiteSpace(task.Description)) { <br />@task.Description } </p> </td> <td class="@Model.CssClass"> <img src="~/images/Edit.png" class="edit-area button-img" data-id="@task.Id" title="Edit" />

What happens with returning IEnumerable if used with async/await (streaming data from SQL Server with Dapper)?

五迷三道 提交于 2020-03-21 11:47:13
问题 I am using Dapper to stream data from a very large set in SQL Server. It works fine with returning IEnumerable and calling Query() , but when I switch to QueryAsync() , it seems that the program tries to read all of the data from SQL Server instead of streaming. According to this question, it should work fine with buffered: false , which I am doing, but the question says nothing about async/await . Now according to this question, it's not straightforward to do what I want with QueryAsync() .

How to await the results of an IAsyncEnumerable<Task<T>>, with a specific level of concurrency

风格不统一 提交于 2020-03-21 06:51:09
问题 I have an asynchronous stream of tasks, that is generated by applying an async lambda to a stream of items: IAsyncEnumerable<int> streamOfItems = AsyncEnumerable.Range(1, 10); IAsyncEnumerable<Task<string>> streamOfTasks = streamOfItems.Select(async x => { await Task.Delay(100); return x.ToString(); }) The methods AsyncEnumerable.Range and Select above are provided from the System.Linq.Async package. The result I want is a stream of results, expressed as an IAsyncEnumerable<string> . The

How to await the results of an IAsyncEnumerable<Task<T>>, with a specific level of concurrency

此生再无相见时 提交于 2020-03-21 06:51:02
问题 I have an asynchronous stream of tasks, that is generated by applying an async lambda to a stream of items: IAsyncEnumerable<int> streamOfItems = AsyncEnumerable.Range(1, 10); IAsyncEnumerable<Task<string>> streamOfTasks = streamOfItems.Select(async x => { await Task.Delay(100); return x.ToString(); }) The methods AsyncEnumerable.Range and Select above are provided from the System.Linq.Async package. The result I want is a stream of results, expressed as an IAsyncEnumerable<string> . The

UWP Update UI From Async Worker

为君一笑 提交于 2020-03-20 14:44:29
问题 I am trying to implement a long-running background process, that periodically reports on its progress, to update the UI in a UWP app. How can I accomplish this? I have seen several helpful topics, but none have all of the pieces, and I have been unable to put them all together. For example, consider a user who picks a very large file, and the app is reading in and/or operating on the data in the file. The user clicks a button, which populates a list stored on the page with data from the file

UWP Update UI From Async Worker

痴心易碎 提交于 2020-03-20 14:44:01
问题 I am trying to implement a long-running background process, that periodically reports on its progress, to update the UI in a UWP app. How can I accomplish this? I have seen several helpful topics, but none have all of the pieces, and I have been unable to put them all together. For example, consider a user who picks a very large file, and the app is reading in and/or operating on the data in the file. The user clicks a button, which populates a list stored on the page with data from the file

How to debug asp.net core async method using Source Link?

眉间皱痕 提交于 2020-03-19 05:17:12
问题 I am trying to debug asp.net core internals to see what is going on under the hood. I set up .net core debugging in VS Code according to this article: https://github.com/OmniSharp/omnisharp-vscode/wiki/Debugging-into-the-.NET-Framework-itself Now I get .net core sources automatically while debugging and can step into methods, but not async ones . Since I have no source code at hand (it loads on the fly from somewhere) I cannot set a breakpoint in an async method to make debugger stop there. I