Skip to content

Instantly share code, notes, and snippets.

@athap
Created February 19, 2014 03:06
Show Gist options
  • Save athap/9085345 to your computer and use it in GitHub Desktop.
Save athap/9085345 to your computer and use it in GitHub Desktop.
Wait for N or Multiple or Unknown number (Depends on some logic) of ajax request using JQuery
class Test
waitForTwoCalls: () ->
$.when(@firstCall(), @secondCall()).then () =>
doSomeThing()
firstCall: () ->
token = $.Deferred
$.ajax({
url: foo/bar,
....
success: (response) =>
token.resolve
})
secondCall: () ->
token = $.Deferred
$.ajax({
url: foo/bar,
....
success: (response) =>
token.resolve
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment