Guest User

Untitled

a guest
Sep 6th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.66 KB | None | 0 0
  1. function foo() {
  2. var result;
  3.  
  4. $.ajax({
  5. url: '...',
  6. success: function(response) {
  7. result = response;
  8. // return response; // <- I tried that one as well
  9. }
  10. });
  11.  
  12. return result;
  13. }
  14.  
  15. var result = foo(); // It always ends up being `undefined`.
  16.  
  17. function findItem() {
  18. var item;
  19. while(item_not_found) {
  20. // search
  21. }
  22. return item;
  23. }
  24.  
  25. var item = findItem();
  26.  
  27. // Do something with item
  28. doSomethingElse();
  29.  
  30. findItem(function(item) {
  31. // Do something with item
  32. });
  33. doSomethingElse();
  34.  
  35. // Using 'superagent' which will return a promise.
  36. var superagent = require('superagent')
  37.  
  38. // This is isn't declared as `async` because it already returns a promise
  39. function delay() {
  40. // `delay` returns a promise
  41. return new Promise(function(resolve, reject) {
  42. // Only `delay` is able to resolve or reject the promise
  43. setTimeout(function() {
  44. resolve(42); // After 3 seconds, resolve the promise with value 42
  45. }, 3000);
  46. });
  47. }
  48.  
  49.  
  50. async function getAllBooks() {
  51. try {
  52. // GET a list of book IDs of the current user
  53. var bookIDs = await superagent.get('/user/books');
  54. // wait for 3 seconds (just for the sake of this example)
  55. await delay();
  56. // GET information about each book
  57. return await superagent.get('/books/ids='+JSON.stringify(bookIDs));
  58. } catch(error) {
  59. // If any of the awaited promises was rejected, this catch block
  60. // would catch the rejection reason
  61. return null;
  62. }
  63. }
  64.  
  65. // Async functions always return a promise
  66. getAllBooks()
  67. .then(function(books) {
  68. console.log(books);
  69. });
  70.  
  71. var result = foo();
  72. // Code that depends on 'result'
  73.  
  74. foo(function(result) {
  75. // Code that depends on 'result'
  76. });
  77.  
  78. function myCallback(result) {
  79. // Code that depends on 'result'
  80. }
  81.  
  82. foo(myCallback);
  83.  
  84. function foo(callback) {
  85. $.ajax({
  86. // ...
  87. success: callback
  88. });
  89. }
  90.  
  91. function foo(callback) {
  92. $.ajax({
  93. // ...
  94. success: function(response) {
  95. // For example, filter the response
  96. callback(filtered_response);
  97. }
  98. });
  99. }
  100.  
  101. function delay() {
  102. // `delay` returns a promise
  103. return new Promise(function(resolve, reject) {
  104. // Only `delay` is able to resolve or reject the promise
  105. setTimeout(function() {
  106. resolve(42); // After 3 seconds, resolve the promise with value 42
  107. }, 3000);
  108. });
  109. }
  110.  
  111. delay()
  112. .then(function(v) { // `delay` returns a promise
  113. console.log(v); // Log the value once it is resolved
  114. })
  115. .catch(function(v) {
  116. // Or do something else if it is rejected
  117. // (it would not happen in this example, since `reject` is not called).
  118. });
  119.  
  120. function ajax(url) {
  121. return new Promise(function(resolve, reject) {
  122. var xhr = new XMLHttpRequest();
  123. xhr.onload = function() {
  124. resolve(this.responseText);
  125. };
  126. xhr.onerror = reject;
  127. xhr.open('GET', url);
  128. xhr.send();
  129. });
  130. }
  131.  
  132. ajax("/echo/json")
  133. .then(function(result) {
  134. // Code depending on result
  135. })
  136. .catch(function() {
  137. // An error occurred
  138. });
  139.  
  140. function ajax() {
  141. return $.ajax(...);
  142. }
  143.  
  144. ajax().done(function(result) {
  145. // Code depending on result
  146. }).fail(function() {
  147. // An error occurred
  148. });
  149.  
  150. function checkPassword() {
  151. return $.ajax({
  152. url: '/password',
  153. data: {
  154. username: $('#username').val(),
  155. password: $('#password').val()
  156. },
  157. type: 'POST',
  158. dataType: 'json'
  159. });
  160. }
  161.  
  162. if (checkPassword()) {
  163. // Tell the user they're logged in
  164. }
  165.  
  166. checkPassword()
  167. .done(function(r) {
  168. if (r) {
  169. // Tell the user they're logged in
  170. } else {
  171. // Tell the user their password was bad
  172. }
  173. })
  174. .fail(function(x) {
  175. // Tell the user something bad happened
  176. });
  177.  
  178. function foo() {
  179. var jqXHR = $.ajax({
  180. //...
  181. async: false
  182. });
  183. return jqXHR.responseText;
  184. }
  185.  
  186. function foo() {
  187. var httpRequest = new XMLHttpRequest();
  188. httpRequest.open('GET', "/echo/json");
  189. httpRequest.send();
  190. return httpRequest.responseText;
  191. }
  192.  
  193. var result = foo(); // always ends up being 'undefined'
  194.  
  195. function getFive(){
  196. var a;
  197. setTimeout(function(){
  198. a=5;
  199. },10);
  200. return a;
  201. }
  202.  
  203. function onComplete(a){ // When the code completes, do this
  204. alert(a);
  205. }
  206.  
  207. function getFive(whenDone){
  208. var a;
  209. setTimeout(function(){
  210. a=5;
  211. whenDone(a);
  212. },10);
  213. }
  214.  
  215. getFive(onComplete);
  216.  
  217. var request = new XMLHttpRequest();
  218. request.open('GET', 'yourURL', false); // `false` makes the request synchronous
  219. request.send(null);
  220.  
  221. if (request.status === 200) {// That's HTTP for 'ok'
  222. console.log(request.responseText);
  223. }
  224.  
  225. var result = foo();
  226. // code that depends on `result` goes here
  227.  
  228. foo(function(result) {
  229. // code that depends on `result`
  230. });
  231.  
  232. function myHandler(result) {
  233. // code that depends on `result`
  234. }
  235. foo(myHandler);
  236.  
  237. function foo(callback) {
  238. var httpRequest = new XMLHttpRequest();
  239. httpRequest.onload = function(){ // when the request is loaded
  240. callback(httpRequest.responseText);// we're calling our method
  241. };
  242. httpRequest.open('GET', "/echo/json");
  243. httpRequest.send();
  244. }
  245.  
  246. function ajax(a, b, c){ // URL, callback, just a placeholder
  247. c = new XMLHttpRequest;
  248. c.open('GET', a);
  249. c.onload = b;
  250. c.send()
  251. }
  252.  
  253. this.response
  254.  
  255. e.target.response
  256.  
  257. function callback(e){
  258. console.log(this.response);
  259. }
  260. ajax('URL', callback);
  261.  
  262. ajax('URL', function(e){console.log(this.response)});
  263.  
  264. function x(a, b, e, d, c){ // URL, callback, method, formdata or {key:val},placeholder
  265. c = new XMLHttpRequest;
  266. c.open(e||'get', a);
  267. c.onload = b;
  268. c.send(d||null)
  269. }
  270.  
  271. x(url, callback); // By default it's get so no need to set
  272. x(url, callback, 'post', {'key': 'val'}); // No need to set post data
  273.  
  274. var fd = new FormData(form);
  275. x(url, callback, 'post', fd);
  276.  
  277. var fd = new FormData();
  278. fd.append('key', 'val')
  279. x(url, callback, 'post', fd);
  280.  
  281. function x(a, b, e, d, c){ // URL, callback, method, formdata or {key:val}, placeholder
  282. c = new XMLHttpRequest;
  283. c.open(e||'get', a);
  284. c.onload = b;
  285. c.onerror = error;
  286. c.send(d||null)
  287. }
  288.  
  289. function error(e){
  290. console.log('--Error--', this.type);
  291. console.log('this: ', this);
  292. console.log('Event: ', e)
  293. }
  294. function displayAjax(e){
  295. console.log(e, this);
  296. }
  297. x('WRONGURL', displayAjax);
  298.  
  299. function omg(a, c){ // URL
  300. c = new XMLHttpRequest;
  301. c.open('GET', a, true);
  302. c.send();
  303. return c; // Or c.response
  304. }
  305.  
  306. var res = omg('thisIsGonnaBlockThePage.txt');
  307.  
  308. function foo() {
  309. var data;
  310. // or $.get(...).then, or request(...).then, or query(...).then
  311. fetch("/echo/json").then(function(response){
  312. data = response.json();
  313. });
  314. return data;
  315. }
  316.  
  317. var result = foo(); // result is always undefined no matter what.
  318.  
  319. function delay(ms){ // takes amount of milliseconds
  320. // returns a new promise
  321. return new Promise(function(resolve, reject){
  322. setTimeout(function(){ // when the time is up
  323. resolve(); // change the promise to the fulfilled state
  324. }, ms);
  325. });
  326. }
  327.  
  328. function foo() {
  329. // RETURN the promise
  330. return fetch("/echo/json").then(function(response){
  331. return response.json(); // process it inside the `then`
  332. });
  333. }
  334.  
  335. foo().then(function(response){
  336. // access the value inside the `then`
  337. })
  338.  
  339. function* foo(){ // notice the star, this is ES6 so new browsers/node/io only
  340. yield 1;
  341. yield 2;
  342. while(true) yield 3;
  343. }
  344.  
  345. var foo = coroutine(function*(){
  346. var data = yield fetch("/echo/json"); // notice the yield
  347. // code here only executes _after_ the request is done
  348. return data.json(); // data is defined
  349. });
  350.  
  351. var main = coroutine(function*(){
  352. var bar = yield foo(); // wait our earlier coroutine, it returns a promise
  353. // server call done here, code below executes when done
  354. var baz = yield fetch("/api/users/"+bar.userid); // depends on foo's result
  355. console.log(baz); // runs after both requests done
  356. });
  357. main();
  358.  
  359. async function foo(){
  360. var data = await fetch("/echo/json"); // notice the await
  361. // code here only executes _after_ the request is done
  362. return data.json(); // data is defined
  363. }
  364.  
  365. function handleData( responseData ) {
  366.  
  367. // Do what you want with the data
  368. console.log(responseData);
  369. }
  370.  
  371. $.ajax({
  372. url: "hi.php",
  373. ...
  374. success: function ( data, status, XHR ) {
  375. handleData(data);
  376. }
  377. });
  378.  
  379. function callServerAsync(){
  380. $.ajax({
  381. url: '...',
  382. success: function(response) {
  383.  
  384. successCallback(response);
  385. }
  386. });
  387. }
  388.  
  389. function successCallback(responseObj){
  390. // Do something like read the response and show data
  391. alert(JSON.stringify(responseObj)); // Only applicable to JSON response
  392. }
  393.  
  394. function foo(callback) {
  395.  
  396. $.ajax({
  397. url: '...',
  398. success: function(response) {
  399. return callback(null, response);
  400. }
  401. });
  402. }
  403.  
  404. var result = foo(function(err, result){
  405. if (!err)
  406. console.log(result);
  407. });
  408.  
  409. promiseB = promiseA.then(
  410. function onSuccess(result) {
  411. return result + 1;
  412. }
  413. ,function onError(err) {
  414. //Handle error
  415. }
  416. );
  417.  
  418. // promiseB will be resolved immediately after promiseA is resolved
  419. // and its value will be the result of promiseA incremented by 1.
  420.  
  421. search(term: string) {
  422. return this.http
  423. .get(`https://api.spotify.com/v1/search?q=${term}&type=artist`)
  424. .map((response) => response.json())
  425. .toPromise();
  426.  
  427. search() {
  428. this.searchService.search(this.searchField.value)
  429. .then((result) => {
  430. this.result = result.artists.items;
  431. })
  432. .catch((error) => console.error(error));
  433. }
  434.  
  435. // WRONG
  436. var results = [];
  437. theArray.forEach(function(entry) {
  438. doSomethingAsync(entry, function(result) {
  439. results.push(result);
  440. });
  441. });
  442. console.log(results); // E.g., using them, returning them, etc.
  443.  
  444. var results = [];
  445. var expecting = theArray.length;
  446. theArray.forEach(function(entry, index) {
  447. doSomethingAsync(entry, function(result) {
  448. results[index] = result;
  449. if (--expecting === 0) {
  450. // Done!
  451. console.log("Results:", results); // E.g., using the results
  452. }
  453. });
  454. });
  455.  
  456. function doSomethingWith(theArray, callback) {
  457. var results = [];
  458. var expecting = theArray.length;
  459. theArray.forEach(function(entry, index) {
  460. doSomethingAsync(entry, function(result) {
  461. results[index] = result;
  462. if (--expecting === 0) {
  463. // Done!
  464. callback(results);
  465. }
  466. });
  467. });
  468. }
  469. doSomethingWith(theArray, function(results) {
  470. console.log("Results:", results);
  471. });
  472.  
  473. function doSomethingWith(theArray) {
  474. return new Promise(function(resolve) {
  475. var results = [];
  476. var expecting = theArray.length;
  477. theArray.forEach(function(entry, index) {
  478. doSomethingAsync(entry, function(result) {
  479. results[index] = result;
  480. if (--expecting === 0) {
  481. // Done!
  482. resolve(results);
  483. }
  484. });
  485. });
  486. });
  487. }
  488. doSomethingWith(theArray).then(function(results) {
  489. console.log("Results:", results);
  490. });
  491.  
  492. function doSomethingWith(theArray) {
  493. return Promise.all(theArray.map(function(entry) {
  494. return doSomethingAsync(entry, function(result) {
  495. results.push(result);
  496. });
  497. }));
  498. }
  499. doSomethingWith(theArray).then(function(results) {
  500. console.log("Results:", results);
  501. });
  502.  
  503. function doSomethingWith(theArray, callback) {
  504. var results = [];
  505. doOne(0);
  506. function doOne(index) {
  507. if (index < theArray.length) {
  508. doSomethingAsync(theArray[index], function(result) {
  509. results.push(result);
  510. doOne(index + 1);
  511. });
  512. } else {
  513. // Done!
  514. callback(results);
  515. }
  516. }
  517. }
  518. doSomethingWith(theArray, function(results) {
  519. console.log("Results:", results);
  520. });
  521.  
  522. async function doSomethingWith(theArray) {
  523. const results = [];
  524. for (const entry of theArray) {
  525. results.push(await doSomethingAsync(entry));
  526. }
  527. return results;
  528. }
  529. doSomethingWith(theArray).then(results => {
  530. console.log("Results:", results);
  531. });
  532.  
  533. function doSomethingWith(theArray) {
  534. return theArray.reduce(function(p, entry) {
  535. return p.then(function(results) {
  536. return doSomethingAsync(entry).then(function(result) {
  537. results.push(result);
  538. return results;
  539. });
  540. });
  541. }, Promise.resolve([]));
  542. }
  543. doSomethingWith(theArray).then(function(results) {
  544. console.log("Results:", results);
  545. });
  546.  
  547. function doSomethingWith(theArray) {
  548. return theArray.reduce((p, entry) => p.then(results => doSomethingAsync(entry).then(result => {
  549. results.push(result);
  550. return results;
  551. })), Promise.resolve([]));
  552. }
  553. doSomethingWith(theArray).then(results => {
  554. console.log("Results:", results);
  555. });
  556.  
  557. var app = angular.module('plunker', []);
  558.  
  559. app.controller('MainCtrl', function($scope,$http) {
  560.  
  561. var getJoke = function(){
  562. return $http.get('http://api.icndb.com/jokes/random').then(function(res){
  563. return res.data.value;
  564. });
  565. }
  566.  
  567. getJoke().then(function(res) {
  568. console.log(res.joke);
  569. });
  570. });
  571.  
  572. var async = require("async");
  573.  
  574. // This wires up result back to the caller
  575. var result = {};
  576. var asyncTasks = [];
  577. asyncTasks.push(function(_callback){
  578. // some asynchronous operation
  579. $.ajax({
  580. url: '...',
  581. success: function(response) {
  582. result.response = response;
  583. _callback();
  584. }
  585. });
  586. });
  587.  
  588. async.parallel(asyncTasks, function(){
  589. // result is available after performing asynchronous operation
  590. console.log(result)
  591. console.log('Done');
  592. });
  593.  
  594. $(document).ready(function(){
  595. function foo() {
  596. $.ajax({url: "api/data", success: function(data){
  597. fooDone(data); //after we have data, we pass it to fooDone
  598. }});
  599. };
  600.  
  601. function fooDone(data) {
  602. console.log(data); //fooDone has the data and console.log it
  603. };
  604.  
  605. foo(); //call happens here
  606. });
  607.  
  608. if (!name) {
  609. name = async1();
  610. }
  611. async2(name);
  612.  
  613. async1(name, callback) {
  614. if (name)
  615. callback(name)
  616. else {
  617. doSomething(callback)
  618. }
  619. }
  620.  
  621. async1(name, async2)
  622.  
  623. var Fiber = require('fibers')
  624.  
  625. function async1(container) {
  626. var current = Fiber.current
  627. var result
  628. doSomething(function(name) {
  629. result = name
  630. fiber.run()
  631. })
  632. Fiber.yield()
  633. return result
  634. }
  635.  
  636. Fiber(function() {
  637. var name
  638. if (!name) {
  639. name = async1()
  640. }
  641. async2(name)
  642. // Make any number of async calls from here
  643. }
  644.  
  645. function callback(response) {
  646. // Here you can do what ever you want with the response object.
  647. console.log(response);
  648. }
  649.  
  650. $.ajax({
  651. url: "...",
  652. success: callback
  653. });
  654.  
  655. [
  656. "search?type=playlist&q=%22doom%20metal%22",
  657. "search?type=playlist&q=Adele"
  658. ]
  659.  
  660. -H "Authorization: Bearer {your access token}"
  661.  
  662. function $http(apiConfig) {
  663. return new Promise(function (resolve, reject) {
  664. var client = new XMLHttpRequest();
  665. client.open(apiConfig.method, apiConfig.url);
  666. client.send();
  667. client.onload = function () {
  668. if (this.status >= 200 && this.status < 300) {
  669. // Performs the function "resolve" when this.status is equal to 2xx.
  670. // Your logic here.
  671. resolve(this.response);
  672. }
  673. else {
  674. // Performs the function "reject" when this.status is different than 2xx.
  675. reject(this.statusText);
  676. }
  677. };
  678. client.onerror = function () {
  679. reject(this.statusText);
  680. };
  681. });
  682. }
  683.  
  684. $http({
  685. method: 'get',
  686. url: 'google.com'
  687. }).then(function(response) {
  688. console.log(response);
  689. }, function(error) {
  690. console.log(error)
  691. });
  692.  
  693. (async function(){
  694.  
  695. var response = await superagent.get('...')
  696. console.log(response)
  697.  
  698. })()
  699.  
  700. var ajaxGet = function (ctx,url) {
  701. var res = {};
  702. var ex;
  703. $.ajax(url)
  704. .done(function (data) {
  705. res.data = data;
  706. })
  707. .fail(function(e) {
  708. ex = e;
  709. })
  710. .always(function() {
  711. ctx.resume(ex);
  712. });
  713. return res;
  714. };
  715. ajaxGet.nsynjsHasCallback = true;
  716.  
  717. function process() {
  718. console.log('got data:', ajaxGet(nsynjsCtx, "data/file1.json").data);
  719. }
  720.  
  721. nsynjs.run(process,this,function () {
  722. console.log("synchronous function finished");
  723. });
  724.  
  725. function doAjax(callbackFunc, method, url) {
  726. var xmlHttpReq = new XMLHttpRequest();
  727. xmlHttpReq.open(method, url);
  728. xmlHttpReq.onreadystatechange = function() {
  729.  
  730. if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) {
  731. callbackFunc(xmlHttpReq.responseText);
  732. }
  733.  
  734.  
  735. }
  736. xmlHttpReq.send(null);
  737.  
  738. }
  739.  
  740. function loadMyJson(categoryValue){
  741. if(categoryValue==="veg")
  742. doAjax(print,"GET","http://localhost:3004/vegetables");
  743. else if(categoryValue==="fruits")
  744. doAjax(print,"GET","http://localhost:3004/fruits");
  745. else
  746. console.log("Data not found");
  747. }
  748.  
  749. function* myGenerator() {
  750. const callback = yield;
  751. let [response] = yield $.ajax("https://stackoverflow.com", {complete: callback});
  752. console.log("response is:", response);
  753.  
  754. // examples of other things you can do
  755. yield setTimeout(callback, 1000);
  756. console.log("it delayed for 1000ms");
  757. while (response.statusText === "error") {
  758. [response] = yield* anotherGenerator();
  759. }
  760. }
  761.  
  762. const gen = myGenerator(); // Create generator
  763. gen.next(); // Start it
  764. gen.next((...args) => gen.next([...args])); // Set its callback function
  765.  
  766. const [err, data] = yield fs.readFile(filePath, "utf-8", callback);
  767.  
  768. var lat = "";
  769. var lon = "";
  770. function callback(data) {
  771. lat = data.lat;
  772. lon = data.lon;
  773. }
  774. function getLoc() {
  775. var url = "http://ip-api.com/json"
  776. $.getJSON(url, function(data) {
  777. callback(data);
  778. });
  779. }
  780.  
  781. getLoc();
  782.  
  783. function foo(result) {
  784. $.ajax({
  785. url: '...',
  786. success: function(response) {
  787. result.response = response; // Store the async result
  788. }
  789. });
  790. }
  791.  
  792. var result = { response: null }; // Object to hold the async result
  793. foo(result); // Returns before the async completes
  794.  
  795. function foo(){
  796. // do something
  797. return 'wohoo';
  798. }
  799.  
  800. let bar = foo(); // bar is 'wohoo' here
  801.  
  802. function foo(){
  803. setTimeout( ()=>{
  804. return 'wohoo';
  805. }, 1000 )
  806. }
  807.  
  808. let bar = foo() // bar is undefined here
  809.  
  810. function foo(){
  811. return new Promise( (resolve, reject) => { // I want foo() to PROMISE me something
  812. setTimeout ( function(){
  813. // promise is RESOLVED , when exececution reaches this line of code
  814. resolve('wohoo')// After 1 second, RESOLVE the promise with value 'wohoo'
  815. }, 1000 )
  816. })
  817. }
  818.  
  819. let bar ;
  820. foo().then( res => {
  821. bar = res;
  822. console.log(bar) // will print 'wohoo'
  823. });
  824.  
  825. function foo() {
  826. var result;
  827.  
  828. $.ajax({
  829. url: '...',
  830. success: function(response) {
  831. myCallback(response);
  832. }
  833. });
  834.  
  835. return result;
  836. }
  837.  
  838. function myCallback(response) {
  839. // Does something.
  840. }
  841.  
  842. __pragma__ ('alias', 'S', '$')
  843.  
  844. def read(url: str):
  845. deferred = S.Deferred()
  846. S.ajax({'type': "POST", 'url': url, 'data': { },
  847. 'success': lambda d: deferred.resolve(d),
  848. 'error': lambda e: deferred.reject(e)
  849. })
  850. return deferred.promise()
  851.  
  852. async def readALot():
  853. try:
  854. result1 = await read("url_1")
  855. result2 = await read("url_2")
  856. except Exception:
  857. console.warn("Reading a lot failed")
  858.  
  859. var milk = order_milk();
  860. put_in_coffee(milk);
  861.  
  862. order_milk(put_in_coffee);
  863.  
  864. order_milk(function(milk) { put_in_coffee(milk, drink_coffee); }
  865.  
  866. var answer;
  867. $.ajax('/foo.json') . done(function(response) {
  868. callback(response.data);
  869. });
  870.  
  871. function callback(data) {
  872. console.log(data);
  873. }
  874.  
  875. order_milk() . then(put_in_coffee)
  876.  
  877. order_milk() . then(put_in_coffee) . then(drink_coffee)
  878.  
  879. function get_data() {
  880. return $.ajax('/foo.json');
  881. }
  882.  
  883. get_data() . then(do_something)
  884.  
  885. get_data() .
  886. then(function(data) { console.log(data); });
  887.  
  888. get_data() .
  889. then(data => console.log(data));
  890.  
  891. a();
  892. b();
  893.  
  894. a() . then(b);
  895.  
  896. async function morning_routine() {
  897. var milk = await order_milk();
  898. var coffee = await put_in_coffee(milk);
  899. await drink(coffee);
  900. }
  901.  
  902. async function foo() {
  903. data = await get_data();
  904. console.log(data);
  905. }
  906.  
  907. async function foo() {
  908. var response = await $.ajax({url: '...'})
  909. return response;
  910. }
  911.  
  912. (async function() {
  913. try {
  914. var result = await foo()
  915. console.log(result)
  916. } catch (e) {}
  917. })()
  918.  
  919. foo().then(response => {
  920. console.log(response)
  921.  
  922. }).catch(error => {
  923. console.log(error)
  924.  
  925. })
  926.  
  927. while (queue.waitForMessage()) {
  928. queue.processNextMessage();
  929. }
  930.  
  931. 1. call foo.com/api/bar using foobarFunc
  932. 2. Go perform an infinite loop
  933. ... and so on
  934.  
  935. function foobarFunc (var) {
  936. console.log(anotherFunction(var));
  937. }
  938.  
  939. function foo(bla) {
  940. console.log(bla)
  941. }
Add Comment
Please, Sign In to add comment