async-await

How do I erase the type of future in the new future API?

扶醉桌前 提交于 2020-01-06 05:15:17
问题 The following does not compile #![feature(await_macro, async_await, futures_api)] use core::future::Future; async fn foo() {} trait Bar { type Output: Future<Output = ()>; fn bar(&self) -> Self::Output; } impl Bar for () { type Output = Box<dyn Future<Output = ()>>; fn bar(&self) -> Self::Output { Box::new(foo()) } } async fn buz() { await!(().bar()) } error[E0277]: the trait bound `(dyn std::future::Future<Output=()> + 'static): std::marker::Unpin` is not satisfied --> src/lib.rs:19:15 | 19

Using Async/Await in Firebase

混江龙づ霸主 提交于 2020-01-06 04:37:10
问题 I'm making a call to firestore with an array of member ids - looking to get back the photoURL property for each and render via jsx. I checked memberAvatars and it's returning fine, but I get this error: Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead. Here is the code I'm using. It is meant to render each cell in an ant table using their render prop. async getMemberAvatars(members) { let

What is the best way to use async/await inside onAuthStateChanged() of Firebase?

你离开我真会死。 提交于 2020-01-06 04:33:21
问题 I'm using Firebase authentication with async/await in React Native. I'm looking for a better way to await inside firebase function. So my question is What is the best way to use async/await inside firebase.auth().onAuthStateChanged() ? Now, I implement it in this way. Create a async function inside onAuthStateChanged() and call itself. Like the example below... However, I think it looks weird. firebase.auth().onAuthStateChanged(user => { const asyncFunc = async () => { await doSomething(); }

Async TypeScript function return jQuery promise

天涯浪子 提交于 2020-01-05 12:16:13
问题 I'm trying to build an MVC like controller in TypeScript and I'm having difficulty getting my async method to return a deferred promise. Here's my function signature: static async GetMatches(input: string, loc?: LatLng):JQueryPromise<any> { The compiler tells me that a 'JQueryPromise' is not a valid async function return type. I would have thought that something like this would be the most common use case for an async function but I can't find any examples. Any help? 回答1: JQueryPromise does

Async TypeScript function return jQuery promise

五迷三道 提交于 2020-01-05 12:15:31
问题 I'm trying to build an MVC like controller in TypeScript and I'm having difficulty getting my async method to return a deferred promise. Here's my function signature: static async GetMatches(input: string, loc?: LatLng):JQueryPromise<any> { The compiler tells me that a 'JQueryPromise' is not a valid async function return type. I would have thought that something like this would be the most common use case for an async function but I can't find any examples. Any help? 回答1: JQueryPromise does

Multiple Task Continuation

丶灬走出姿态 提交于 2020-01-05 08:38:24
问题 I would like to understand this scenario a little clearer: Consider the following code: frmProgressAsync prog = new frmProgressAsync(true); TaskWithProgress t = new TaskWithProgress("Smoothing CP", true); t.Task = A.ShowMovingAverage(tension,t.Progress) .ContinueWith(prev => { t.ProgressInformation.Report("Smoothing FG"); B.ShowMovingAverage(tension, t.Progress); }); await prog.RunAsync(t); I have two tasks I wish to run A.ShowMovingAverage and B.ShowMovingAverage . Both return a Task. In the

Any difference between “await Task.Run(); return;” and “return Task.Run()”?

a 夏天 提交于 2020-01-05 07:29:11
问题 Is there any conceptual difference between the following two pieces of code: async Task TestAsync() { await Task.Run(() => DoSomeWork()); } and Task TestAsync() { return Task.Run(() => DoSomeWork()); } Does the generated code differ, either? EDIT: To avoid confusion with Task.Run , a similar case: async Task TestAsync() { await Task.Delay(1000); } and Task TestAsync() { return Task.Delay(1000); } LATE UPDATE: In addition to the accepted answer, there is also a difference in how

Promises and async/await in nodejs

北战南征 提交于 2020-01-05 07:08:29
问题 My sample code: let name; Login.findOne().then(() => { name = 'sameer'; }); // consider this is async code console.log(name); So the above code works async, so now my console.log became undefined. I used callbacks to make the code work like synchronous. My callback code: let name; const callback = () => { console.log(name); }; Login.findOne().then(() => { name = 'sameer'; callback(); }); Now its working perfectly, My question is how you replace this small code with promises and async await

Calling async method from non async method

不羁的心 提交于 2020-01-05 04:44:07
问题 Here is my code in doing so but it seems like I could not do other things once it started calling the async function and then the app will not respond. I would like to just run it to the background. I'm doing a search and in every 3 letters, it will call the api to get datas if have match. Once I have input 3 letters, it then it calls to the API and I could not input more letters because the app is not responding. How to call the async function and will just run in the background so that I

Code after Task.Delay in delegate not executing

落花浮王杯 提交于 2020-01-05 03:48:51
问题 I am trying to concurrently process partitions of a list. For each integer in each partition of the list I am trying to wait for that amount of time. public class Program { public async static void Main() { Console.WriteLine("Starting."); var values = Enumerable.Range(0,1000).ToList(); await Task.WhenAll( from partition in Partitioner.Create(values).GetPartitions(10) select Task.Run(async delegate { Console.WriteLine("Entered"); using (partition) while (partition.MoveNext()){ var delay =