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.

50995 questions
6623
votes
42 answers

How do I return the response from an asynchronous call?

How do I return the response/result from a function foo that makes an asynchronous request? 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 one, but none…
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
3134
votes
34 answers

How can I upload files asynchronously with jQuery?

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
  • 76,835
  • 68
  • 152
  • 179
1387
votes
26 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
  • 32,492
  • 24
  • 78
  • 114
1361
votes
22 answers

Asynchronous vs synchronous execution. What is the difference?

What is the difference between asynchronous and synchronous execution?
tush1r
  • 19,443
  • 14
  • 36
  • 35
1325
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
  • 21,497
  • 10
  • 48
  • 68
907
votes
7 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é
  • 69,329
  • 26
  • 129
  • 166
897
votes
13 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…
Stas Bichenko
  • 13,013
  • 8
  • 45
  • 83
845
votes
12 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
  • 13,045
  • 12
  • 43
  • 67
750
votes
28 answers

How would I run an async Task method synchronously?

I am 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
  • 130,264
  • 66
  • 304
  • 490
696
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
  • 8,762
  • 6
  • 32
  • 41
623
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
  • 113,358
  • 34
  • 211
  • 239
572
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
  • 16,587
  • 26
  • 100
  • 160
566
votes
19 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
  • 9,217
  • 7
  • 26
  • 28
500
votes
4 answers

WaitAll vs WhenAll

What is the difference between Task.WaitAll() and Task.WhenAll() from the Async CTP? Can you provide some sample code to illustrate the different use cases?
Yaron Levi
  • 12,535
  • 16
  • 69
  • 118
486
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
  • 11,367
  • 10
  • 47
  • 61
1
2 3
99 100