Questions tagged [asynchronous]

15904 questions
0

votes
0

answer
4

Views

Getting DOMException with playing video onload

I want to play a video when the website is loaded. For that I am using the following code: window.onload = function webisteLoaded() { var main_bg_video = document.getElementById('main_bg_video'); main_bg_video.play(); } Your browser does not support HTML5 video. Additional info: I import the s...
Filip Degenhart
1

votes
1

answer
1.9k

Views

NodeJS, get return value from async await

I have an async await function that uses mongoose: const createModelB = async (id) => { try { let user = await User.findOne({id: id}); if (user) { let modelB = new ModelB({ user_id: user.id }); modelB = await scrum.save(); return modelB; } return null; } catch (err) { console.error(err); } return nu...
Mr.D
1

votes
1

answer
117

Views

Is it possible that async code takes more time than sync?

I have a piece of code that execute HTTP requests (inside a loop) from some currency API and do some work on the data which received. Because it was slow, I changed it to asynchronously function using: Task.Run() However, when I measure calculation time (using Stopwatch..) of the function with the...
O. Harambam
1

votes
1

answer
124

Views

UITests failing when run in group but succeed when run independently

I'm currently working on a project with many asynchronous code and I'm writing the UITests for this project. During the development I run them one by one but never in a group. So I thought the tests are succeeding. But when testing them all together most of them are failing. I implemented the setup...
Tom Kuschka
1

votes
1

answer
221

Views

Thread Context and Synchronization Context

I see the use of terms Thread Context and Synchronization Context being used in documents regarding threading. Do they refer to the same thing? This is the definition for thread context by Microsoft: The thread context includes all the information the thread needs to seamlessly resume execution, i...
John L.
1

votes
1

answer
134

Views

How to properly wait until future is complete in dart

There is a slight bug in my app made with Flutter, that when the user has signed in, it fetches the user information from my database but not fast enough and causes a visual error on my front end of the app. The app has layouts that use the user information (name, location, and image) and it is not...
user3152311
1

votes
1

answer
38

Views

Self-sizing UICollectionView cells with async image loading

I have a horizontal UICollectionView in which I display images that are loaded asynchronously. The cells are supposed to have their width fit the image. In viewDidLoad of my view controller, I set the estimated cell size: (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.estimate...
LinusGeffarth
1

votes
1

answer
67

Views

Calling async methods (Vert.x, Java) from necessarily synchronous ones

We have a set of Java applications that were originally written using normal synchronous methods but have largely been converted to asynchronous Vert.x (the regular API, not Rx) wherever it makes sense. We're having some trouble at the boundaries between sync and async code, especially when we have...
clixtec
1

votes
3

answer
74

Views

Executing N times a Scala Future

I am trying to find a more elegant way to execute 2 times a function which returns a Future[HttpReponse] and then to use the response of the 2-end call. for { // function post returns a Future[HttpResponse] response
Martin
1

votes
1

answer
66

Views

Maximize number of parallel requests (aiohttp)

tl;dr: how do I maximize number of http requests I can send in parallel? I am fetching data from multiple urls with aiohttp library. I'm testing its performance and I've observed that somewhere in the process there is a bottleneck, where running more urls at once just doesn't help. I am using this c...
pieca
1

votes
1

answer
44

Views

variable not available after for-loop inside Promise.then()

I'm using a for-loop containing an if statement inside of a Promise.then() (it's an api call). A variable initialized before the for-loop is available within the for-loop, but not after. I've console.logged the variable before the for-loop, just inside the for-loop, inside the if statement, after th...
skillit zimberg
1

votes
1

answer
41

Views

Main thread exits before the completion of CompletableFuture

CompletableFuture feature = CompletableFuture.supplyAsync (() -> composeMethod ( )). thenAccept (s -> System.out.println ('wassup java' + s)). thenRun (() -> System.out.println (' imm immortal')); nonblockingmethod ( ); This is the CompletableFuture future example im working on private static...
javaworld
1

votes
1

answer
42

Views

Can a button both redirect and perform a function with asynchronous JavaScript

I have reviewed a few similar posts on here but everything I have found so far is using href to redirect to a totally new webpage. I have a button in my JavaScript code which uses the Material-UI This button both redirects the webpage and calls a function which initiates a server request. Now thi...
user8735495
1

votes
1

answer
43

Views

Is Promise a technique to realize asynchronous programming?

I've tried to understand Promise from google source, and haven't found how it execute code asynchronously. My understanding of asynchronous function is that code below it can be resolved at a time before it. For example: setTimeout(()=>{console.log('in')}, 5000); console.log('out'); // output: // o...
hashtabe_0
1

votes
1

answer
52

Views

How do I do an async query without enumerating the data?

I'm trying to work out how to write a generic async GetAll database method in Entity Framework Core without enumerating the data. I want GetAll to be async, but don't want it to enumerate the data, so that I can add a Where method afterwards, and have that applied to the database query.. List custom...
Avrohom Yisroel
1

votes
1

answer
54

Views

How to consume this EF Core C# async method in F#?

I am using F# with Entity Framework and I can't get my head around consuming C# async methods from F#. Despite others SO answers related to similar issues can't really get my head around. Here is my attempt with the code below, initially synchronous: let getAirport (id: Guid) = use context = new MyC...
Ehouarn Perret
1

votes
2

answer
57

Views

How To Know All Asynchronous HTTP Calls are Completed

I am trying to figure out how to determine if all async HTTP GET requests I've made have completed, so that I can execute another method. For context, I have something similar to the code below: public void init() throws IOException { Map mapOfObjects = new HashMap(); ObjectMapper mapper = new Objec...
Pr0pagate
1

votes
0

answer
6

Views

Light Gulp 4 task still throwing 'async completion' error

I've not used Gulp before, so I'm not migrating an old gulpfile to Gulp 4. I'm just trying to get a few basic tasks set up. However, regardless of the method I use to signal async completion as well documented in this post I still get the 'Did you forget to signal async completion?' error. 'use stri...
webermn15
0

votes
0

answer
23

Views

How can I maintain a chaining of results approach while performing a non-blocking wait?

Background: I use a Result class that lets me chain success and failure lambdas together. For example: var result = DoSomething(); result.OnSuccess(() => DoSomethingElse()).OnFailure(() => LogFailure()); One of the OnSuccess functions I have is: public Result OnSuccess(Func func) { if (!this.Success...
Craig
0

votes
2

answer
19

Views

“Program does not contain a static 'Main' method suitable for an entry point” when adding async

So I have been fiddling around with Web responses and requests in C# and I received a problem when I tried to run the program. One of the lines of code I had: var response = await httpClient.SendAsync(request); required async in the method making private static void Main(string[] args) into private...
Sheng Plays
-1

votes
1

answer
26

Views

Need help to remove .get() usage with Java CompletableFuture

I am having trouble refactoring my code to remove .get() usages. Simplified problem goes like this: get a record, update it, then return some information. If the record does not exist, create a new record, then return some information. Pseudo version of working code: String getInfo(String id, Stri...
CrystalSquire
-1

votes
0

answer
23

Views

Why does this function never run even if it did before?

I'm using React.js & Web3.js to create a dapp. I believe this question is more related to react.js and javascript and that's why I'm not posting in in Ethereum Stackexchange. Consider the following code: allowAddress = async() => { let approvedAddress = this.state.approvedAddress; let approvedValue...
Sophie259
1

votes
1

answer
601

Views

Mapper.Map<Task<IEnumerable<Address>>, Task<IEnumerable<AddressView>>()

.NET Framework 4.5.2, .Asp.NET Web API 5.2.3, AutoMapper 5.1.1 I have the following ASP.NET MVC WebApi Action Method on the AddressController. For my test I return only 10 records as you can see in service method below: [Route('api/Address/GetAllAsync')] [HttpGet] public async Task GetAllAsync() { A...
user1798599
10

votes
0

answer
353

Views

UWP SendToAsync from Socket results in AddressFamilyNotSupported

I am using the Socket class from UWP to send data via UDP to a specific device. The problem is that after a few send forth and back, my SocketAsyncEventArgs for Sending gets stuck and in SocketError i got AddressFamilyNotSupported. Initializing of the classes is done like this m_Socket = new Socket...
Cyriac
1

votes
1

answer
312

Views

SKProductsRequestDelegate method isn't being called inside class

I want to load the SKProducts before the actual page is shown. But I have some difficulties with creating it. What I thought was to made another class that loads the products, like this: class GetIapInfo: NSObject, SKProductsRequestDelegate { var list = [SKProduct]() var p = SKProduct() let audio =...
da1lbi3
1

votes
3

answer
746

Views

Alternative to using async () => in Rx Finally

My understanding is that async void, should be avoided and that async () => is just async void in disguise when used with Action. Hence, using the Rx.NET Finally operator asynchronously with async () => should be avoided since Finally accepts Action as parameter: IObservable.Finally(async () => { a...
Jasper H Bojsen
1

votes
1

answer
2.3k

Views

Using async in event emitter

I am being challenged trying to make an async call inside an event. Here's the code from Nodemailer - I've added the line where I need to make an async call: let transporter = nodemailer.createTransport({ SES: new aws.SES({ apiVersion: '2010-12-01' }), sendingRate: 1 // max 1 messages/second }); //...
cyberwombat
0

votes
1

answer
16

Views

How to store async fetched response to an array object

I have an async fuction which successfully retrieves a json object but I can't store this output in an array/variable which I want to use outside the function itself. 'use strict' const fetch = require('node-fetch') async function getValue() { let response = await fetch('https://api.pro.coinbase.com...
Mamba76
1

votes
3

answer
1.7k

Views

python - webdriver and asyncio

Is it possible open browser for each task firstly, and load links after that ? This code raises an error import asyncio from selenium import webdriver async def get_html(url): driver = await webdriver.Chrome() response = await driver.get(url) TypeError: object WebDriver can't be used in 'await'...
Valek Potapov
1

votes
3

answer
67

Views

How to convert synchronous method to asynchronous without changing it's signature

I have a large scale C# solution with 40-ish modules. I'm trying to convert a service used solution-wide from synchronous to asynchronous. the problem is I can't find a way to do so without changing the signature of the method. I've tried wrapping said asynchronous desired operation with Task but t...
oren k
1

votes
3

answer
60

Views

Python, How to make an asynchronous data generator?

I have a program that loads data and processes it. Both loading and processing take time, and I'd like to do them in parallel. Here is the synchronous version of my program (where the 'loading' and 'processing' are done in sequence, and are trivial operations here for the sake of the example): im...
Peter
1

votes
1

answer
76

Views

How can I unit test an Asynchronous method in F#?

I've got a method that returns a task I'm trying to test synchonously in F#. Here's the method, which is an implementation of a C# interface: member this.RunAsync(): System.Threading.Tasks.Task = async{ this._settings.LogSettings |> Seq.iter(fun settings -> this.clearLogs(settings)) |>...
reckface
1

votes
1

answer
66

Views

Choosing not to await async function in action in ASP.NET Core WebAPI controller

The scenario is the following: Backend: Asp.NET Core WebAPI 2.2 Frontend: iOS and Android which consumes the API I have a function allowing the user to send messages to other users. The sending of a message is done in an asynchronous action: public async Task CreateMessage This action does the foll...
solojuve1897
1

votes
3

answer
46

Views

Async Function in Node.js

I have an endpoint in my Node.js API which returns a JSON array of results provided by the Google-Search-Scrapper library. app.get('/google_image_search', (req, res) => { var options = { query: 'grenouille', age: 'y', // last 24 hours ([hdwmy]\d? as in google URL) limit: 10, params: {} // params wil...
Waggoner_Keith
1

votes
2

answer
71

Views

How to unit test a UIButton that calls an asynchronous task

I am trying to test a login method triggered by a IBAction that if the login failed (if the completion hander returned a error), I want to present an alert controller, but the login method is obviously an asynchronous. The loginUser method is already mocked and always returns handler(nil, .EmptyData...
Brendon Cheung
1

votes
1

answer
45

Views

Can await and then be mixed in one implementation?

I'm wondering if await and .then can be used in the same async function? Here is my function: uploadImageToImgur: async function (file) { return new Promise(function(resolve, reject) { const url = 'https://api.imgur.com/3/image', reader = new FileReader(); if (file) { reader.readAsDataURL(file); }...
JKowalski
1

votes
3

answer
61

Views

How can I properly execute an asynchronous method from a ViewModel?

For the purposes of this question, I've got a simple Window with the following XAML: Check Whenever the users enters text in the TextBox or checks the CheckBox, I'd like to perform a slow task (such as saving my model's state to disk). Here's the view model: public class ViewModel : ViewModelBase /...
redcurry
1

votes
2

answer
77

Views

Correctly implementing Tasks in a WPF application

I'm looking for some advice on getting to grips with Tasks in WPF and was wondering if anyone could have a look over my code and point out what I'm doing incorrectly? Basically the application takes a postcode from the UI which is used to instantiate a Task service which will get Longitude/Latitude...
Luke Dee
1

votes
2

answer
76

Views

Using async/await to find the value of a cors request?

I'm attempting to execute a CORS request, then use async/await to get value out of it (I'm using jquery btw). The functions createCORSRequest and executeCORSRequest both work fine I believe, so the implementation doesn't really matter. The function getDailyGames uses await to receive a promise crea...
16jacobj
0

votes
0

answer
29

Views

Returning a value from a nested asynchronous function in JavaScript [duplicate]

This question already has an answer here: How do I return the response from an asynchronous call? 34 answers Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference 6 answers I went through similar problems in this website and none of them worked for my c...
user2979303

View additional questions