async-await

Asyncio execution flow issue

梦想与她 提交于 2021-02-08 04:52:12
问题 i am a little new to asyncio in python. I was trying to run this simple code but i don't know why i am getting this unexpected output. What i did is that, in outer function, i created async tasks and stored it in an array tasks . Before awaiting on these tasks i wrote a print statement print("outer") that should run in every iteration. And inside the task i wrote another print statement print("inner") in inner function. But some how i am getting some unexpected output. Here's the code -

Why HttpContext.Current is not null in async/await with ConfigureAwait

荒凉一梦 提交于 2021-02-08 03:39:55
问题 I have a library async function called from controller. I expected HttpContext.Current to be null after await with ConfigureAwait(false) everywhere, but in controller it is not null. Can somebody explain why? //in libraby public class MyClass { public async Task WaitAsync() { await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); var httpContext = System.Web.HttpContext.Current; // null, OK } } public class HomeController : Controller { public async Task<ActionResult> Index() { var

Async Generator: Yielding a rejected promise

◇◆丶佛笑我妖孽 提交于 2021-02-07 21:54:23
问题 I've been playing around with async generators in an attempt to make a "promise ordering" generator which takes an array of promises and yields out promises one by one in the order they resolve or reject. So something like: async function* orderProms(prom_arr) { // Make a copy so the splices don't mess it up. const proms = [...prom_arr]; while (proms.length) { // Tag each promise with it's index, so that we can remove it for the next loop. const {prom, index} = await Promise.race(proms.map(

Async odbc seems to be synchronous

不羁岁月 提交于 2021-02-07 18:43:24
问题 I'm trying to do async database queries, but when I test my code it appears to be synchronous. I've isolated the issue to my Query function. Can't figure out what I'm doing wrong, I'm pretty new to the aync/await functionality so it's possible that I've done something stupid :) This is the failing code: (i'm using a local install of postgresql) public static void Main() { Task.Run(async () => await MainAsync()).GetAwaiter().GetResult(); } public static async Task MainAsync() { await

List.add() async task await correct syntax

两盒软妹~` 提交于 2021-02-07 18:38:43
问题 Hello I am trying to add items to a list asynchronously but I am not sure how it is done and if I am using an incorrect syntax, this is what I have at the moment: My View: await viewModel.getMessages(); list.ItemsSource = viewModel.Messages; My View Model: public List<Message> Messages { get; set; } public async Task getMessages() { await GetRemoteMessages(); } private async Task GetRemoteMessages() { var remoteClient = new ChiesiClient(); var messages = await remoteClient.getMessages()

Angular 4 loading tree structure in recursive observable calls

╄→尐↘猪︶ㄣ 提交于 2021-02-07 18:32:32
问题 Hi I'm pretty new to Observables and I'm looking for a way of loading my navigation tree with recursive observable calls. The Navigation should be build up dynamically base on all the index.json files in the directory and sub directories. Only the url of the first call is static: /public/index.json This is the directory structure. Each directory may contain a index.json , providing information about its content and may references to other index files via the loadChildrenFromUrl property. |

Angular 4 loading tree structure in recursive observable calls

天涯浪子 提交于 2021-02-07 18:32:07
问题 Hi I'm pretty new to Observables and I'm looking for a way of loading my navigation tree with recursive observable calls. The Navigation should be build up dynamically base on all the index.json files in the directory and sub directories. Only the url of the first call is static: /public/index.json This is the directory structure. Each directory may contain a index.json , providing information about its content and may references to other index files via the loadChildrenFromUrl property. |

Unit testing async method - test never completes

霸气de小男生 提交于 2021-02-07 14:53:49
问题 I'm trying to unit test my a class I'm building that calls a number of URLs (Async) and retrieves the contents. Here's the test I'm having a problem with: [Test] public void downloads_content_for_each_url() { _mockGetContentUrls.Setup(x => x.GetAll()) .Returns(new[] { "http://www.url1.com", "http://www.url2.com" }); _mockDownloadContent.Setup(x => x.DownloadContentFromUrlAsync(It.IsAny<string>())) .Returns(new Task<IEnumerable<MobileContent>>(() => new List<MobileContent>())); var

How do i call an async method from a winforms button click event?

纵饮孤独 提交于 2021-02-07 14:47:24
问题 I have an I/O bound method that I want to run asynchronously. In the help docs it mentions that I should use async and await without Task.Run to quote For I/O-bound code, you await an operation which returns a Task or Task inside of an async method. How do I do this from a winforms button click event? I have tried private void button_Click(object sender, EventArgs e) { await doLoadJob(); } private async Task<int> doLoadJob() { await loadJob(); return 0; } 回答1: Your button_Click method needs

How do i call an async method from a winforms button click event?

孤人 提交于 2021-02-07 14:44:25
问题 I have an I/O bound method that I want to run asynchronously. In the help docs it mentions that I should use async and await without Task.Run to quote For I/O-bound code, you await an operation which returns a Task or Task inside of an async method. How do I do this from a winforms button click event? I have tried private void button_Click(object sender, EventArgs e) { await doLoadJob(); } private async Task<int> doLoadJob() { await loadJob(); return 0; } 回答1: Your button_Click method needs