async-await

Xamarin ProgressBar not updating real time

若如初见. 提交于 2020-01-15 05:15:07
问题 All, I'm fairly new to Xamarin and more notably, C# so please, be kind ...! I have a Xamarin.Forms application that drops down to .iOS using a DependencyService which then traverses all of the songs on my device and returns using a custom "Song" model. There's no doubt a better way to do it but in order to return the album artwork back to the PCL, I've taken the iOS UIImage and turned it into a System.IO.Stream object and am returning that through the Song model. Adding this artwork

Down-side on calling async function without await

南楼画角 提交于 2020-01-15 04:42:06
问题 Given the code with async async function wierdFunction(){ setTimeout(function(){ //background process that does not return //Russian roulette if ( Math.random() > 0.99 ) throw new Error('Bang!'); }, 3000); } I only need to call this function asynchronous, I don't need to know when it finished. app.post('/wierd-endpoint', function (req,res){ wierdFunction(); res.json({status:"Running. Now, go away."}); }); Is there any advise against calling it without await keyword? 回答1: Just remove the async

how to do async await on a forEach function [duplicate]

天涯浪子 提交于 2020-01-15 03:39:40
问题 This question already has answers here : Using async/await with a forEach loop (18 answers) Closed 2 years ago . I'm a beginner in async await and promises. I read few articles and watch few tutorial videos but I am still not able to understand it completely. So I have a code that I'm working on right now }).then(function() { var responseArray = [] [url1,url2,url3,url4].forEach((url)=>{ makeRequest(url) }).then((response)=>{ responseArray.push(response) }) return responseArray }) So as

Is it possible continue a stopped async function?

天大地大妈咪最大 提交于 2020-01-14 22:55:10
问题 I'm trying to learn about promises, and I wonder about to start and stop an async function, like my example show. It starts at the begining and stop when you click the button, but it seems can't continue. var stop = 0; var elParrafo = document.getElementById('miParrafo'); function sendStop() { stop = 1; } function sendStart() { stop = 0; } function esperar(ms) { return new Promise(function(resolve, reject) { setTimeout(resolve, ms) }); } async function trabajar() { while (stop === 0) {

Is the use of [ThreadStatic] at odds with asynchronous code?

旧街凉风 提交于 2020-01-14 19:34:05
问题 We have a fairly large existing code base for various webservices built on top of ASP.NET and that code makes heavy use of accessing HttpContext.Current.User (wrapped as Client.User ) which I'm fairly sure internally uses [ThreadStatic] to give you that ambient scoping. I'm currently looking into if it's possible that we start to use more asynchronous code in the form of async/await but I'm having a hard time finding how the use of [ThreadStatic] fits into this. Removing the reliance on

What's the difference between the call/return protocol of oldstyle and newstyle coroutines in Python?

旧巷老猫 提交于 2020-01-14 13:02:42
问题 I'm transitioning from old-style coroutines (where 'yield' returns a value supplied by 'send', but which are otherwise essentially generators) to new-style coroutines with 'async def' and 'await'. There are a couple of things that really puzzle me. Consider the following old-style coroutine that computes the running average of numbers supplied to it by 'send', at each point returning the mean-so-far. (This example is from Chapter 16 of Fluent Python by Luciano Ramalho.) def averager(): total

Interface naming convention for method returning Task [closed]

戏子无情 提交于 2020-01-14 10:19:20
问题 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 5 years ago . Consider the following interface and implementations. interface IService { Task<string> GetAnswer(string question); } class SomeService : IService { async Task<string> IService.GetAnswer(string question) { ... code using awaits ... } } class AnotherService : IService { Task

Cancel Async Task from a button

旧城冷巷雨未停 提交于 2020-01-14 09:10:35
问题 What I need to do is be able to cancel a task that is running async. I have been searching and cannot seem to wrap my head around it. I just cant seem to discern how it would be implemented into my current setup. Here is my code that fires my task off. Any help on where or how to implement a cancellation token would be greatly appreciated. private async void startThread() { //do ui stuff before starting ProgressLabel.Text = String.Format("0 / {0} Runs Completed", index.Count()); ProgressBar

async await returning Task<List<T>> instead of List<T> on calling aync method

╄→гoц情女王★ 提交于 2020-01-14 09:04:18
问题 I am trying to understand the usage of async await and i studied few blog posts and now i have made a testing code but it is not working the way i am expecting it to work. I have a method which returns List: private List<Employee> GetEmployees() { IList<Employee> list = new List<Employee>(); list.Add(new Employee() { Id = 1, Age = 20, Name = "Kavin" }); list.Add(new Employee() { Id = 2, Age = 30, Name = "Alen" }); list.Add(new Employee() { Id = 3, Age = 20, Name = "Suresh" }); list.Add(new

karma-typescript: import JS file with Async keyword

不羁岁月 提交于 2020-01-14 07:48:11
问题 I'm using karma-typescript, with this karma config file : karmaTypescriptConfig: { compilerOptions: { target: "es5", lib: ["dom", "es2015", "es2017"] }, bundlerOptions: { transforms: [require("karma-typescript-es6-transform")()] } }, In my spec files, I have this code : import {} from './local/lib.js' In my lib.js, I have this code : async function() {} When executing my tests with npm test , I have this error : ERROR [source-reader.karma-typescript] Error parsing code: Unexpected token (X:Y)