synchronous

Nodejs Synchronous For each loop

陌路散爱 提交于 2019-12-03 19:05:08
问题 I want to do a for each loop but have it run synchronously. Each iteration of the loop will do an http.get call and that will return json for it to insert the values into a database. The problem is that the for loop runs asynchronously and that causes all of the http.gets to all run at once and my database doesn't end up inserting all of the data.I am using async-foreach to try to do what I want it to do, but I don't have to use it if I can do it the right way. mCardImport = require('m

How do I write a blocking synchronous method in Javascript?

南笙酒味 提交于 2019-12-03 13:53:19
I'm trying to mock out a method which takes a long time for testing purposes but can't find a good way to do this in Javascript. Any good approaches besides writing a very long for loop? How about a loop that checks time ? function sleep(milliSeconds){ var startTime = new Date().getTime(); // get the current time while (new Date().getTime() < startTime + milliSeconds); // hog cpu until time's up } You could make a synchronous AJAX call to a server which defers the response by a certain amount of time as requested by your script. Note however that this method won't work in Firefox as it doesn't

node.js — execute command synchronously and get result

爷,独闯天下 提交于 2019-12-03 13:20:48
I'm trying to execute a child_process synchronously in node.js (Yes, I know this is bad, I have a good reason) and retrieve any output on stdout, but I can't quite figure out how... I found this SO post: node.js execute system command synchronously that describes how to use a library (node-ffi) to execute the command, and this works great, but the only thing I'm able to get is the process exit code. Any data the command executes is sent directly to stdout -- how do I capture this? > run('whoami') username 0 in otherwords, username is echo'd to stdout, the result of run is 0 . I'd much rather

Lightweight way of waiting for a group of asynchronous Java calls

南楼画角 提交于 2019-12-03 12:57:49
问题 We're writing some code, in a single blocking method, which calls out to multiple, slow third party services asynchronously. These async calls are wrapped in code that implement the same interface method. We wish to fire off the async calls and wait until they've all returned before returning our blocking method call. I hope that's clear! Is there a suitable design pattern / library for implementing this... it must be a fairly common pattern. Thanks in advance. 回答1: You could use a

Synchronous Ajax - does Chrome have a timeout on trusted events?

假装没事ソ 提交于 2019-12-03 11:38:14
问题 Situation We have a situation, where we need to onclick-open a new tab in browsers after performing an XHR / Ajax request . We do this by setting the Ajax request to be performed synchronously to keep the context of the trusted click event and this works fine. Problem However, in the latest Chrome version (36), we experience popup warnings when the Ajax call has some lag... A lag of 2 seconds is enough for Chrome to display a popup warning instead of opening the tab like it is supposed to.

Can someone please explain how startActivity(intent) and startActivityForResult(intent) are Asynchronous?

隐身守侯 提交于 2019-12-03 10:51:12
If an Asynchronous thread is a thread that operates separately to the main thread and doesn't interfere with the main thread... Does a new Activity not occupy the main thread after it has been started through startActivity(intent) ? The majority of what I have read on this says these are both asynchronous, however there are a fair few conflicting answers and the people that say this don't really give convincing arguments. So if anyone who has this clear in their head and could explain why they are synchronous/asynchronous, I would be a very grateful man! Cheers EDIT: So the answer I have

Asynchronous google ads versus Synchronous

主宰稳场 提交于 2019-12-03 09:28:14
问题 I'm using google DFP. If I use synchronous ads from google, my site loads slowly as it needs to load the ad at the same time it loads the website, and if an ad takes long to respond, then the load of the page gets paused. If I use asynchronous ads, this is not a problem since the page will load wether or not ads are loaded. In other words, it makes the site load faster. The thing is, using asynchronous ads creates a div with fixed width and height no matter if there are ads displaying or not.

how to use Promise with express in node.js?

戏子无情 提交于 2019-12-03 08:56:20
问题 I am using Promise with Express. router.post('/Registration', function(req, res) { var Promise = require('promise'); var errorsArr = []; function username() { console.log("1"); return new Promise(function(resolve, reject) { User.findOne({ username: req.body.username }, function(err, user) { if(err) { reject(err) } else { console.log("2"); errorsArr.push({ msg: "Username already been taken." }); resolve(errorsArr); } }); }); } var username = username(); console.log(errorsArr); }); When I log

Starting and Forgetting an Async task in MVC Action

我的未来我决定 提交于 2019-12-03 07:29:26
I have a standard, non-async action like: [HttpPost] public JsonResult StartGeneratePdf(int id) { PdfGenerator.Current.GenerateAsync(id); return Json(null); } The idea being that I know this PDF generation could take a long time, so I just start the task and return, not caring about the result of the async operation. In a default ASP.Net MVC 4 app this gives me this nice exception: System.InvalidOperationException: An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page

What methods are blocking in Javascript?

本小妞迷上赌 提交于 2019-12-03 06:23:58
I'm trying to override the standard confirm() method in Javascript (make a nice UI and stuff). I've read a 100 posts that it "can't be done", but I don't want to give up until I have given it a fair shot. :) So, the real problem is of course that the confirm() method must block all javascript execution until the user selects an option. So, what are the methods in Javascript that have blocking behavior? I've been able to come up with 5: alert() - does not suit me, because it displays an unwanted UI of its own; confirm() - the same problem as alert() ; infinite loop - even modern browsers will