Questions tagged [asynchronous]

Asynchronous programming is a strategy for deferring operations with high latency or low priority, usually in an attempt to improve performance, responsiveness, and / or composability of software. Such strategies are usually employed using some combination of event-driven programming and callbacks, and optionally making use of concurrency through coroutines and / or threads.

Asynchronous programming is a strategy for deferring operations with high latency or low priority, usually in an attempt to improve performance, responsiveness, and / or composability of software. Such strategies are usually employed using some combination of event-driven programming and callbacks, and optionally making use of concurrency through coroutines and / or threads.

Asynchronous programming is used in many situations:

  • handling user input in UIs and games,
  • processing network traffic,
  • performing disk I/O,
  • batching work,
  • and more.

Asynchronous programming models can aid in software composition in many languages (notably languages where functions are first-class types) and APIs providing callback-based completion messaging. Proper use of this programming methodology can improve throughput and improve responsiveness by reducing total latency of job batches when executed in parallel. This approach can also result in an increase in system throughput at the cost of increased operational latency resulting from deferred processing.

44778 questions
5960
votes
42 answers

How to return the response from an asynchronous call?

I have a function foo which makes an asynchronous request. How can I return the response/result from foo? I am trying to return the value from the callback, as well as assigning the result to a local variable inside the function and returning that…
Felix Kling
  • 705,106
  • 160
  • 1,004
  • 1,072
3020
votes
34 answers

How can I upload files asynchronously?

I would like to upload a file asynchronously with jQuery. $(document).ready(function () { $("#uploadbutton").click(function () { var filename = $("#file").val(); $.ajax({ type: "POST", url:…
Sergio del Amo
  • 71,609
  • 66
  • 148
  • 177
1288
votes
22 answers

Asynchronous vs synchronous execution, what does it really mean?

What is the difference between asynchronous and synchronous execution?
tush1r
  • 18,129
  • 14
  • 32
  • 34
1255
votes
14 answers

How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?

I have a JavaScript widget which provides standard extension points. One of them is the beforecreate function. It should return false to prevent an item from being created. I've added an Ajax call into this function using jQuery: beforecreate:…
Artem Tikhomirov
  • 20,413
  • 10
  • 43
  • 66
1186
votes
25 answers

How and when to use ‘async’ and ‘await’

From my understanding one of the main things that async and await do is to make code easy to write and read - but is using them equal to spawning background threads to perform long duration logic? I'm currently trying out the most basic example.…
Dan Dinu
  • 28,044
  • 21
  • 67
  • 100
803
votes
6 answers

Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference

Given the following examples, why is outerScopeVar undefined in all cases? var outerScopeVar; var img = document.createElement('img'); img.onload = function() { outerScopeVar = this.width; }; img.src = 'lolcat.png'; alert(outerScopeVar); var…
Fabrício Matté
  • 65,581
  • 23
  • 120
  • 159
781
votes
11 answers

Why do we need middleware for async flow in Redux?

According to the docs, "Without middleware, Redux store only supports synchronous data flow". I don't understand why this is the case. Why can't the container component call the async API, and then dispatch the actions? For example, imagine a…
sbichenko
  • 11,613
  • 7
  • 43
  • 81
681
votes
25 answers

How would I run an async Task method synchronously?

I'm learning about async/await, and ran into a situation where I need to call an async method synchronously. How can I do that? Async method: public async Task GetCustomers() { return await Service.GetCustomersAsync(); } Normal…
Rachel
  • 122,023
  • 59
  • 287
  • 465
613
votes
12 answers

What are the best use cases for Akka framework

I have heard lots of raving about Akka framework (Java/Scala service platform), but so far have not seen many actual examples of use cases it would be good for. So I would be interested in hearing about things developers have used it…
StaxMan
  • 102,903
  • 28
  • 190
  • 229
595
votes
10 answers

Call async/await functions in parallel

As far as I understand, in ES7/ES2016 putting multiple await's in code will work similar to chaining .then() with promises, meaning that they will execute one after the other rather than in parallel. So, for example, we have this code: await…
Victor Marchuk
  • 10,195
  • 10
  • 36
  • 62
569
votes
6 answers

async/await - when to return a Task vs void?

Under what scenarios would one want to use public async Task AsyncMethod(int num) instead of public async void AsyncMethod(int num) The only scenario that I can think of is if you need the task to be able to track its progress. Additionally, in…
user981225
  • 7,403
  • 6
  • 27
  • 40
514
votes
3 answers

How to return value from an asynchronous callback function?

This question is asked many times in SO. But still I can't get stuff. I want to get some value from callback. Look at the script below for clarification. function foo(address){ // google map stuff geocoder.geocode( { 'address':…
Gowri
  • 15,559
  • 25
  • 95
  • 154
490
votes
16 answers

Can't specify the 'async' modifier on the 'Main' method of a console app

I am new to asynchronous programming with the async modifier. I am trying to figure out how to make sure that my Main method of a console application actually runs asynchronously. class Program { static void Main(string[] args) { …
danielovich
  • 7,859
  • 7
  • 23
  • 28
479
votes
10 answers

AngularJS : Initialize service with asynchronous data

I have an AngularJS service that I want to initialize with some asynchronous data. Something like this: myModule.service('MyService', function($http) { var myData = null; $http.get('data.json').success(function (data) { myData =…
testing123
  • 10,987
  • 10
  • 42
  • 59
424
votes
13 answers

asynchronous and non-blocking calls? also between blocking and synchronous

What is the difference between asynchronous and non-blocking calls? Also between blocking and synchronous calls (with examples please)?
user331561
  • 4,331
  • 3
  • 14
  • 5
1
2 3
99 100