async-await

Why values are not inserted into DynamoDB unless calling `.promise()`?

倖福魔咒の 提交于 2020-05-15 09:25:29
问题 I have some simple async code in a lambda, fetching some data and then inserting that into DynamoDB. With this code, everything works as expected: const AWS = require('aws-sdk'); const docClient = new AWS.DynamoDB.DocumentClient({ region: 'eu-west-1', apiVersion: 'latest' }); function fetchSomething() { return new Promise((resolve) => { setTimeout(() => { resolve({ foo: 'Foo', bar: 'Bar' }); }, 2000); }) } exports.handler = async (event) => { try { const data = await fetchSomething(); const

Return IAsyncEnumerable from an async method

橙三吉。 提交于 2020-05-15 09:23:05
问题 Take the following the methods: public async IAsyncEnumerable<int> Foo() { await SomeAsyncMethod(); return Bar(); // Throws since you can not return values from iterators } public async IAsyncEnumerable<int> Bar() { for(int i = 0; i < 10; i++) { await Task.Delay(100); yield return i; } } I wonder what the best practice would be, to do, what the code above tries to. Basically returning an IAsyncEnumerable from an async method. For myself I can imagine two ways: Iterating over the

aws lambda function async connection query

非 Y 不嫁゛ 提交于 2020-05-15 08:39:04
问题 I have a function connect to amazon RDS and select data from a table, but my callback function always return result is undefined. I used async/await for this function but it does't work. My problem: I need function getOrder must be finished and return a result, after that call to callback. My function: 'use strict'; let mysql = require('mysql'); let config = require('./config'); let pool = mysql.createPool({ connectionLimit : 10, host : config.host, user : config.user, password : config

Async Pattern - waiting for an Event before returning some value from a method

依然范特西╮ 提交于 2020-05-15 06:54:45
问题 [Disclaimer - this code is simplified (a lot) to easy reading and I know it doesent conform to normal code standards] My problem can bee seen in the code below. Basically I have a caller that parses in an object. I have to wait until a subcomponent is finished - which is signaled by an event - before returning a value from that that is based on some value on the subcomponent. The question is: What is the preferred pattern for situations like this (of course an actual solution would be most

Async Pattern - waiting for an Event before returning some value from a method

别来无恙 提交于 2020-05-15 06:53:05
问题 [Disclaimer - this code is simplified (a lot) to easy reading and I know it doesent conform to normal code standards] My problem can bee seen in the code below. Basically I have a caller that parses in an object. I have to wait until a subcomponent is finished - which is signaled by an event - before returning a value from that that is based on some value on the subcomponent. The question is: What is the preferred pattern for situations like this (of course an actual solution would be most

Multiple Response.writeAsync Calls

不羁的心 提交于 2020-05-15 05:27:11
问题 I have been researching Asp.Net Security and I found some surprising code: Strange Code? context.Response.ContentType = "text/html"; await context.Response.WriteAsync("<html><body>"); await context.Response.WriteAsync("An remote error has occured: " + context.Request.Query["ErrorMessage"] + "<br>"); await context.Response.WriteAsync("<a href=\"/\">Home</a>"); await context.Response.WriteAsync("</body></html>"); What surprised me is the multiple calls to WriteAsync with short strings. What I

IAsyncOperation<IReadOnlyList<UserNotification>>' does not contain a definition for 'GetAwaiter' [duplicate]

不想你离开。 提交于 2020-05-15 05:19:04
问题 This question already has answers here : FromBluetoothAddressAsync IAsyncOperation does not contain a definition for 'GetAwaiter' error (2 answers) Closed last year . I am using Visual Studio 2017 Professional. I have been following this guide: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener My problem code is as follows: using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System

Attempting ValidationAttribute in MVC4 that is asynchronous using Async, Task and Await

∥☆過路亽.° 提交于 2020-05-15 03:35:31
问题 I am attempting to write a Validation attribute in MVC4. The purpose is to check for the existence of an application reference (just a string that represents a key I wish to prevent a duplicate for). My data is accessed via WebAPI and because I am using 4.5 I wish to make this asynchronous if possible. I am perhaps not making the best or appropriate usage of async and await but I would like to know how to call my async method from the overridden IsValid method of the inherited Validation

Attempting ValidationAttribute in MVC4 that is asynchronous using Async, Task and Await

ⅰ亾dé卋堺 提交于 2020-05-15 03:35:25
问题 I am attempting to write a Validation attribute in MVC4. The purpose is to check for the existence of an application reference (just a string that represents a key I wish to prevent a duplicate for). My data is accessed via WebAPI and because I am using 4.5 I wish to make this asynchronous if possible. I am perhaps not making the best or appropriate usage of async and await but I would like to know how to call my async method from the overridden IsValid method of the inherited Validation

Execute promise in synchronous batches javascript

ⅰ亾dé卋堺 提交于 2020-05-15 02:29:08
问题 I have a promise function that receives a row from rows array to a remote server. const post = (row) => new Promise(resolve=> { //do post then, resolve(response.data); } So, I want to create a function that iterate through the array and execute post for each element in constant size batches. Before the execution of next batch, current batch should be resolved completely. How can I achieve this? 回答1: can use Promise.all for the batch and await for resolve: const post = (row) => new Promise