async-await

languageext Either.Map/Bind with a Task in the Right position

冷暖自知 提交于 2020-01-07 06:18:47
问题 I am using the toolkit languageext package for C# and am running into a problem with the Either class when the Right value is some kind of Task. For some reason this is causing a hang: var res = repo.GetAccountWithID(accountID) .Map(c => filesServiceCustomer.Initialize(c)) .Bind(t => t.Result); Here, GetAccountWithID returns an Either<Exception, Account> and the Initialize method take an Account and returns a Task<Either<Exception, bool>> . However, it would appear that either the Map or Bind

Tasks not finishing before process end

冷暖自知 提交于 2020-01-07 04:52:07
问题 In my code in the main thread I call a 3rd party API. For each result from the API I call 2 async tasks. Sometimes all works perfectly, sometimes not all async tasks run. I suppose that when the main thread finishes, the garbage collector kills all my other tasks that run in the background. Is there any way to tell garbage collector not to kill the background services when the main thread finishes? The code is like this: for (int i = 0; i < 1000; i++) { var demo = new AsyncAwaitTest(); demo

2 Async tasks in parallel and waiting for results - .Net

穿精又带淫゛_ 提交于 2020-01-07 03:09:11
问题 I intend to run two tasks in parallel and wait for both of them to finish. Here is my two tasks: Private Async Function tempWorker1() As Task For i = 1 To 5000 If i Mod 100 = 0 Then Console.WriteLine("From 1:{0}", i) End If Next End Function Private Async Function tempWorker2() As Task For i = 1 To 5000 If i Mod 100 = 0 Then Console.WriteLine("From 2:{0}", i) End If Next End Function I run them as: Dim task1 As Task = tempWorker1() Dim task2 As Task = tempWorker2() Await Task.WhenAll(task1,

Winform - changing a method to async/await

不羁岁月 提交于 2020-01-07 02:02:36
问题 I have a winform with six listbox side-by-side. Under each listbox there is a textbox and a Button labeled "Add." When you put something in the textbox and press the Add button, using EF, I update a table for that listbox and I re- dataBind the listbox . Here's a sample of one of the event handlers for Add button: private void btnOfferType_Click(object sender, EventArgs e) { TypeCategoryAdd("OfferType", tbOfferType.Text.Trim()); } TypeCategoryAdd function is listed below. I want to do this

async/await return Promise { <pending> }

泪湿孤枕 提交于 2020-01-06 13:10:43
问题 my question is: why does this log 'promise {pending}' despite of i used async/await? I checked similar questions and answers on them and it seems like it should be okay but it is not. How do i change it to get the result and why? Thank you. const rp = require('request-promise-native'); async function sampleFunc() { let sample = await rp({ uri: 'http://google.com', jar: true }); return sample; } async function f() { return await sampleFunc(); } console.log( f()); 回答1: async-await is really

NetworkStream ReadAsync and WriteAsync hang infinitelly when using CancellationTokenSource - Deadlock Caused by Task.Result (or Task.Wait)

烂漫一生 提交于 2020-01-06 08:07:29
问题 After reading pretty much every question on Stack Overflow and Microsoft's documentation about NetworkStream, I dont understand what is wrong with my code. The problem I see is that my method GetDataAsync() hangs very often. I call this method from Init Method like so: public MyView(string id) { InitializeComponent(); MyViewModel myViewModel = session.Resolve<MyViewModel>(); //Autofac myiewModel.Init(id); BindingContext = myViewModel; } Above, my View does its initialization, then resolves

Function does not wait until Promise is resolved

余生长醉 提交于 2020-01-06 07:53:08
问题 I'm developing a simple discord bot and I am attempting to print some general data about a certain player. I recently learned about async/await and I attempted to implement it into my code. It does not seem to work however because when I first trigger this code, it prints null but on subsequent triggers it will print the correct data, indicating that my function did not wait for the Promise to resolve. async function stats(){ data = await NBA.stats.playerInfo({ PlayerID: curry.playerId }); }

Why await a promise doesn't wait the promise to resolve?

亡梦爱人 提交于 2020-01-06 06:08:45
问题 I am trying to learn to use properly async await but I am kind of cofused about it. In the snippets, I am trying to build an array of object containing the infos I need about the file I am uploading in the component. The problem is that the objects in this.fileInfo are not exactly waiting the promise to return the encoded images, returning this output as I console.log this.fileInfo: As you can see, the key image is a ZoneAwarePromise whose value is undefined. Can you please help me to fix

“await task.ConfigureAwait(false)” versus “await ContextSwitcher.SwitchToThreadPool()” [closed]

允我心安 提交于 2020-01-06 05:36:06
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last month . It's widely recommended to use ConfigureAwait(false) like this: await Do1Async().ConfigureAwait(false); // ... await Do2Async().ConfigureAwait(false); // ... await Do3Async().ConfigureAwait(false); // ... IIRC, at the same time it's widely discouraged to use something like

Understanding synchronous code using node.js async/await with mysql pool

£可爱£侵袭症+ 提交于 2020-01-06 05:22:16
问题 I want to create an initialisation file for a simple browser game. I'm using Node.js v8.10.0 and MySQL Ver 14.14 Distrib 5.7.27. Actually what I want to do would be very straightforward with a synchronous language like Java but I would like to do everything in Node.js. I tried to understand promises and async/await for days but I have unexpected results I cannot find explanations for. Important precision: I want the program to finish by itself when everything is done. The problem is already