async-await

Properly handling HttpClient exceptions within async / await

*爱你&永不变心* 提交于 2020-06-22 06:45:49
问题 I was hoping somebody could enlighten me a little bit on an issue I am facing in regards to async/await exception handling with HttpClient. I have written some code to illustrate, and it is being excecuted on both a Windows Phone 8 device and the emulator: private async void SearchButton_Click(object sender, EventArgs e) { try { HttpClient client = new HttpClient(); System.Diagnostics.Debug.WriteLine("BEGIN FAULTY REQUEST:"); string response = await client.GetStringAsync("http://www

How to detect source code changes in async method body

丶灬走出姿态 提交于 2020-06-18 11:56:10
问题 I'm trying to detect during runtime if the source code of a method of a class has been changed. Basically I retrieve the method body (IL), hash it with md5 and store it in the database. Next time I check the method, I can compare the hashes. public class Changed { public string SomeValue { get; set; } public string GetSomeValue() { return SomeValue + "add something"; } public async Task<string> GetSomeValueAsync() { return await Task.FromResult(SomeValue + "add something"); } } I'm using Mono

Async, Await EventHandler return value

无人久伴 提交于 2020-06-17 13:25:08
问题 I'm trying to upload a file into S3bucket using with AWS Sdk for .Net. I'm uploading a file like below: Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button2.Click Await AddFileToFolderAsync(file, bucketName, fld) ' here file is file's fullpath,buckatename is ' available s3bucket name, ' fld is target folder path into that s3bucket. End Sub Public Async Function AddFileToFolderAsync(FileName As String, bucketName As String, folderName() As String) As Task Try If

CORS error when using await import() with Google API

烂漫一生 提交于 2020-06-17 13:20:16
问题 Why I get a CORS error: Access to script at 'https://maps.googleapis.com/maps/api/js' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. When I try to import dynamically Google Maps API in my JavaScript : await import('https://maps.googleapis.com/maps/api/js') But not when I do it in my HTML : <script defer src="https://maps.googleapis.com/maps/api/js"></script> Any idea would be really appreciate it. Note : if I

forEach() iterates too fast with ASYNC AWAIT - Skipping data

为君一笑 提交于 2020-06-17 09:56:27
问题 I am re-writing my website and am trying to import my members from array of JSON objects. Each object represents a band that the user has uploaded. So I wrote a quick file that works with the list and my new database / authentication system, auth0. As outline in the comments below... First I Request an access token so I can create an account for each member using Auth0. Then I iterate through my array of objects representing bands. For each band object I have the code do a few things... First

Async/Await in Express Middleware

落花浮王杯 提交于 2020-06-17 01:52:33
问题 I'm having trouble understanding how to properly write middleware in Express that utilizes async/await, but doesn't leave a Promise floating in the ether after it's execution. I've read a ton of blogs and StackOverflow posts, and it seems like there is some consensus around using the following pattern in async/await middleware: const asyncHandler = fn => (req, res, next) => Promise .resolve(fn(req, res, next)) .catch(next) app.use(asyncHandler(async (req, res, next) => { req.user = await User

Counter not increasing in async map function

◇◆丶佛笑我妖孽 提交于 2020-06-16 20:47:19
问题 I am working with mongodb and nodejs. I have an array of customers I have to create each inside database. const promises2 = customers.map(async customer => { if (!customer.customerId) { const counter = await Counter.findOne({ type: "Customer" }); console.log({counter}); const payload = { customerId: counter.sequence_value, }; await Customer.create(payload); await Counter.findOneAndUpdate({ type: "Customer" }, { $inc: { sequence_value: 1 } }); } }); await Promise.all([...promises2]); The issue

How to implement tasks with two awaiting points, using async/await

和自甴很熟 提交于 2020-06-16 17:48:15
问题 I have some asynchronous operations that consist of two distinct stages. Initially I want to await them until the completion of their first stage, and later await them until their final completion. Here is a simplified version of these operations: async Task<string> TwoStagesAsync() { Console.WriteLine($"Stage 1 Started"); await Task.Delay(1000); // Simulate an I/O operation bool resultOfStage1 = true; Console.WriteLine($"Stage 1 Finished"); if (!resultOfStage1) return null; /* Stage

How to implement tasks with two awaiting points, using async/await

萝らか妹 提交于 2020-06-16 17:46:35
问题 I have some asynchronous operations that consist of two distinct stages. Initially I want to await them until the completion of their first stage, and later await them until their final completion. Here is a simplified version of these operations: async Task<string> TwoStagesAsync() { Console.WriteLine($"Stage 1 Started"); await Task.Delay(1000); // Simulate an I/O operation bool resultOfStage1 = true; Console.WriteLine($"Stage 1 Finished"); if (!resultOfStage1) return null; /* Stage

Use async forEach loop while fetching data from firestore

自作多情 提交于 2020-06-16 07:57:28
问题 I have firestore data somewhat like this: "Support": { "userid":"abcdxyz", "message": "hello" } I am using nodejs to fetch my data and I also want to show the email address and name of the person who sent this message. So I am using following function: database.collection("support").get().then(async function (collections) { var data = []; console.log("data collected"); collections.forEach(async function (collection) { var temp = {}; var collectionData = collection.data() var userInfo = await