async-await

refactor promise and promise.all with async await of es2017

泄露秘密 提交于 2020-01-03 15:34:06
问题 I have a working version of a photo upload handler but I would want to see how it work with async await. Before anything below is my working code using promise. onChangePhotos = (e) => { e.preventDefault() let files = e.target.files if(files.length === 0) { return } const allow_photos_length = this.state.selectedAlbum.photos.length + files.length if(allow_photos_length > this.state.maxPhoto) { alert(`Maximum only ${maxPhoto} photos per album!`) return } this.setState({ uploading_photo: true }

Aureliajs Waiting For Data on App Constructor

三世轮回 提交于 2020-01-03 13:43:48
问题 I am developing an app in aureliajs. The development process is started for many months and now, the back-end developers want to make their services versioned. So I have a web service to call to get the version of each server side (web api) app and then, for the further requests, call the right api address including its version. So, in the app.js I am requesting the system meta and storing it somewhere. But some components get initialized before this request gets done. So they won't find the

Entity Framework - lazy loading or additional async/await query method?

折月煮酒 提交于 2020-01-03 13:36:29
问题 I have these Domain Models public class Topic { public int TopicId { get; set; } public virtual ICollection<Post> Posts { get; set; } } public class Post { public int PostId { get; set; } public int? TopicId { get; set; } public virtual Topic Topic { get; set; } } For example I would like to impliment method TestAsync, there I want to work with Topic object and related Posts objects. Topic model I can get using async method and topicId as param. public async Task<bool> TestAsync(int topicId)

Why await only works in async function in javascript?

↘锁芯ラ 提交于 2020-01-03 08:49:10
问题 Just going through this tutorial, and it baffles me to understand why await only works in async function. From the tutorial: As said, await only works inside async function. From my understanding, async wraps the function return object into a Promise, so the caller can use .then() async function f() { return 1; } f().then(alert); // 1 And await just waits for the promise to settle within the async function. async function f() { let promise = new Promise((resolve, reject) => { setTimeout(() =>

Where is Nancy's CancellationToken for async Request Handlers coming from and when is it cancelled?

假如想象 提交于 2020-01-03 08:44:11
问题 This is more a question regarding understanding how and when Nancy might cancel an async request handler via the provided cancellationToken instance. Basically what I am wondering about is in what conditions is the token's .IsCancellationRequested set to true - is this documented or explained somewhere? How does Nancy handle async handlers that 'never' return / in 'time'? And regarding 'in time': is there a timeout / limit after which handlers do get cancelled? 回答1: I know this is an old

Confusion about calling CPU-bound methods synchronously from an async method

孤街醉人 提交于 2020-01-03 08:25:08
问题 I'm getting my feet wet with .NET 4.5's async/await construct. I'm working on a RESTful Web API solution. I'm trying to figure out what to do with CPU-bound operation - 1) call it synchronously from the current thread, or 2) use Task.Run() ? Let's use the example from this page: async Task<int> AccessTheWebAsync() { // You need to add a reference to System.Net.Http to declare client. HttpClient client = new HttpClient(); // GetStringAsync returns a Task<string>. That means that when you await

Why does the Task.WhenAny not throw an expected TimeoutException?

孤街浪徒 提交于 2020-01-03 07:30:54
问题 Please, observe the following trivial code: class Program { static void Main() { var sw = new Stopwatch(); sw.Start(); try { Task.WhenAny(RunAsync()).GetAwaiter().GetResult(); } catch (TimeoutException) { Console.WriteLine("Timed out"); } Console.WriteLine("Elapsed: " + sw.Elapsed); Console.WriteLine("Press Enter to exit"); Console.ReadLine(); } private static async Task RunAsync() { await Observable.StartAsync(async ct => { for (int i = 0; i < 10; ++i) { await Task.Delay(500, ct); Console

How to force execution to stop till asynchronous function is fully executed?

空扰寡人 提交于 2020-01-03 05:22:10
问题 I'm creating a silverlight application for CRM as follow: 1- A usercontrol which is a form is filled with data retrieved from the CRM using async/await 2- A Print button that creates an instance of that usercontrol and prints it I have a problem in the sequence of execution that causes the Print button to print the usercontrol with no data, meaning, it's executed before the async method finishes. My code is as follows: User control: Public partial class ManagerContact : UserControl //

Storing an async function as a variable

♀尐吖头ヾ 提交于 2020-01-03 05:11:45
问题 I have a question that is similar to this question but that differs in that in my case I am dealing with Asynchronous functions. So as the question says I want to store a method in a variable (to call it later) In the case of syncrhonous functions private delegate void eventmethod(); //(for a function without arguments and return void) private eventmethod MySavedEvent; void D() { } MySavedEvent = D; MySavedEvent(); But what happens if the function is actually Task<returnType> D(); How can I

Storing an async function as a variable

强颜欢笑 提交于 2020-01-03 05:11:13
问题 I have a question that is similar to this question but that differs in that in my case I am dealing with Asynchronous functions. So as the question says I want to store a method in a variable (to call it later) In the case of syncrhonous functions private delegate void eventmethod(); //(for a function without arguments and return void) private eventmethod MySavedEvent; void D() { } MySavedEvent = D; MySavedEvent(); But what happens if the function is actually Task<returnType> D(); How can I