synchronous

Simplest way to wait some asynchronous tasks complete, in Javascript?

爷,独闯天下 提交于 2019-11-26 02:28:30
问题 I want to drop some mongodb collections, but that\'s an asynchronous task. The code will be: var mongoose = require(\'mongoose\'); mongoose.connect(\'mongo://localhost/xxx\'); var conn = mongoose.connection; [\'aaa\',\'bbb\',\'ccc\'].forEach(function(name){ conn.collection(name).drop(function(err) { console.log(\'dropped\'); }); }); console.log(\'all dropped\'); The console displays: all dropped dropped dropped dropped What is the simplest way to make sure all dropped will be printed after

Can AFNetworking return data synchronously (inside a block)?

你说的曾经没有我的故事 提交于 2019-11-26 02:20:01
问题 I have a function using AFJSONRequestOperation, and I wish to return the result only after success. Could you point me in the right direction? I\'m still a bit clueless with blocks and AFNetworking specifically. -(id)someFunction{ __block id data; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id json){ data = json; return data; // won\'t work } failure:^(NSURLRequest *request,

document.createElement(“script”) synchronously

风流意气都作罢 提交于 2019-11-26 01:28:13
问题 Is it possible to call in a .js file synchronously and then use it immediately afterward? <script type=\"text/javascript\"> var head = document.getElementsByTagName(\'head\').item(0); var script = document.createElement(\'script\'); script.setAttribute(\'type\', \'text/javascript\'); script.setAttribute(\'src\', \'http://mysite/my.js\'); head.appendChild(script); myFunction(); // Fails because it hasn\'t loaded from my.js yet. window.onload = function() { // Works most of the time but not all

Wait for Shell to finish, then format cells - synchronously execute a command

南笙酒味 提交于 2019-11-26 00:48:20
问题 I have an executable that I call using the shell command: Shell (ThisWorkbook.Path & \"\\ProcessData.exe\") The executable does some computations, then exports results back to Excel. I want to be able to change the format of the results AFTER they are exported. In other words, i need the Shell command first to WAIT until the executable finishes its task, exports the data, and THEN do the next commands to format. I tried the Shellandwait() , but without much luck. I had: Sub Test()

What is the difference between synchronous and asynchronous programming (in node.js)

与世无争的帅哥 提交于 2019-11-25 23:58:13
问题 I\'ve been reading nodebeginner And I came across the following two pieces of code. The first one: var result = database.query(\"SELECT * FROM hugetable\"); console.log(\"Hello World\"); The second one: database.query(\"SELECT * FROM hugetable\", function(rows) { var result = rows; }); console.log(\"Hello World\"); I get what they\'re supposed to do, they query the database to retrieve the answer to the query. And then console.log(\'Hello world\') . The first one is supposedly synchronous

Asynchronous vs synchronous execution, what does it really mean? [closed]

我怕爱的太早我们不能终老 提交于 2019-11-25 23:56:23
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 27 days ago . What is the difference between asynchronous and synchronous execution? 回答1: When you execute something synchronously, you wait for it to finish before moving on to another task. When you execute something asynchronously, you can move on to another task before it finishes. That

Are all javascript callbacks asynchronous? If not, how do I know which are?

流过昼夜 提交于 2019-11-25 23:49:46
问题 I\'m curious as to whether all javascript callbacks are asynchronous, or whether that is the case only in certain situations. Also, I\'m sure what makes javascript code asynchronous (or ways to use asynchronous javascript) differ between the browser and nodejs, so I\'d like to know in each situation what constitutes real asynchronous javascript. I\'m under the impression that in the following scenarion, I\'m not actually writing asynchronous code. function addOne(value){ value = value + 1;

jQuery: Performing synchronous AJAX requests

…衆ロ難τιáo~ 提交于 2019-11-25 22:42:02
问题 I\'ve done some jQuery in the past, but I am completely stuck on this. I know about the pros and cons of using synchronous ajax calls, but here it will be required. The remote page is loaded (controlled with firebug), but no return is shown. What should I do different to make my function to return properly? function getRemote() { var remote; $.ajax({ type: \"GET\", url: remote_url, async: false, success : function(data) { remote = data; } }); return remote; } 回答1: As you're making a

Wait for Shell to finish, then format cells - synchronously execute a command

荒凉一梦 提交于 2019-11-25 22:07:26
I have an executable that I call using the shell command: Shell (ThisWorkbook.Path & "\ProcessData.exe") The executable does some computations, then exports results back to Excel. I want to be able to change the format of the results AFTER they are exported. In other words, i need the Shell command first to WAIT until the executable finishes its task, exports the data, and THEN do the next commands to format. I tried the Shellandwait() , but without much luck. I had: Sub Test() ShellandWait (ThisWorkbook.Path & "\ProcessData.exe") 'Additional lines to format cells as needed End Sub