synchronous

What's a sync and async method?

让人想犯罪 __ 提交于 2020-01-26 04:50:22
问题 What's a sync method and what is an async method ? What's the difference between sync and async methods ? When do I have to use sync or async method ? I'm asking those questions because I don't understand : public async void ReadData(filepath) { CreateDoc("hello"); //<------ Why I can't do that ? } public void CreateDoc(string astring) { Debug.WriteLine(astring); } And why I can't do that ? : public async void ReadData(filepath) { var BarreDroite = new string[] { "|" }; foreach (string

How to use after and each in conjunction to create a synchronous loop in underscore js

微笑、不失礼 提交于 2020-01-25 02:57:09
问题 Hi I'm trying to create a synchronous loop using underscore js. For each loop iteration I make some further asynchronous calls. However, I need to wait until each iteration call is finished before I move on to the next iteration. Is this possible in underscore js ? If yes, how so ? could someone please provide an example ? _.( items ).each( function(item) { // make aync call and wait till done processItem(item, function callBack(data, err){ // success. ready to move to the next item. }); //

Starting and Forgetting an Async task in MVC Action

落花浮王杯 提交于 2020-01-22 12:26:25
问题 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

Logout when closing window in Angular 4

有些话、适合烂在心里 提交于 2020-01-19 14:11:43
问题 I have an Angular 4 applicaton and I want to call the logout function when the user close the page (window or tab of the browser). This is my logout function : let currentUser: User = JSON.parse(localStorage.getItem('currentUser')); let headers = new Headers({ 'Authorization': 'Basic ' + btoa(currentUser.login + ":" + currentUser.password), 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'access-control-allow-headers, access-control

How to load session data before stateProvider state changes in AngularJs?

被刻印的时光 ゝ 提交于 2020-01-17 04:59:07
问题 I'm using angular-acl (https://github.com/mikemclin/angular-acl) to manage the authorization logic of my application and It's working fine, except when the user open a new window/tab. When the user open a new window/tab I cannot access the sessionStorage so I need to reload the acl and the user roles from the API, but as the request is asynchronous it normally resolves after the check for permission. How can I certify that the stateProvider only will change the page after the acl list is

What is the difference between synchronous and asynchronous transmission in TCP/ IP socket programming?

寵の児 提交于 2020-01-13 08:41:26
问题 I am new to C++ and I am trying to develop a client-server application based on the boost::asio library. I am (still) not able to understand properly the difference between sync and async modes. I've previously studied web protocol services such as HTTP and AJAX. From this explanation, it's clear that HTTP is synchronous and AJAX is asynchronous. What is the difference in TCP socket communication in terms of sync and async? And which mode is better from the perspective of enterprise-level

Django no text in response

大兔子大兔子 提交于 2020-01-07 02:56:07
问题 somewhere in my views.py,I have def loadFcs(request): r = requests.get('a url') res = json.loads(r.text) #Do other stuff return HttpResponse('some response') Now when I call this from my javascript, loadFcs gets called, and probably requests.get gets called asynchronously. So I end up seeing ' TypeError at /loadFcs expected string or buffer' and the trace points to the line with res = json.loads(r.text) I also modified my code to check whats the problem, and def loadFcs(request): r = requests

i am using node.js promise for validating either username exist in db or not

陌路散爱 提交于 2020-01-07 01:48:13
问题 i want to check either username exist in mongo db or not i want to do it by promise , i am new in node.js please help me to understand actual scenario thanks in advance. var errorsArr = []; var promise = username(); promise.then(function(data){ errorsArr.push({"msg":"Username already been taken."}); },console.error); username(function(err,data){ User.findOne({"username":req.body.username},function(err,user) { if(err) return console.error(err); return user; }); }); console.log(errorsArr); 回答1:

How to insert data to mongo synchronously (Nodejs, Express)

旧街凉风 提交于 2020-01-05 06:50:26
问题 I have a problem with inserting data to mongo db using node(express) My code looks like this: router.get('/data/:section/:sort', function(req, res, next) { //Deleting old data always before writing new //Image.remove().exec(); var section = req.params.section; var sort = req.params.sort; //Link to Igmur API var url = 'https://api.imgur.com/3/gallery/'+section+'/'+sort+'/1'; //1 at the end is used to get more than 60 images(gives only 60 without it) request.get({ url: url, method: 'GET',

Using RestKit to perform a synchronous request

雨燕双飞 提交于 2020-01-04 01:58:15
问题 - (BOOL)do_a_Restkit_request_and_return_a_boolean { [manager postObject:nil path:@"/mypath" parameters:@{@"password":password} success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { myResult = [mappingResult firstObject] == 5; } failure:^(RKObjectRequestOperation *operation, NSError *error) { }]; return myResult; } Hello I would like to make a RestKit call like the above Synchronous so as to return myResult after the call of the Success block. 回答1: You can use an