logo
down
shadow

Multiple Async series causing wrong behavior in Javascript


Multiple Async series causing wrong behavior in Javascript

By : MOHAMMAD ZOBAIR
Date : November 22 2020, 11:17 AM
it helps some times With asynchronous functions, invoking the callback is analogous to returning from a normal function in the sense that it resumes execution of the rest of the program. In function f1, invoking cb causes f2 to be executed (which eventually prints Hello from f2 and Done all).
To make sure f2 is executed after f11, f12 and f13 have all finished, the call to cb should be moved to the final callback of the inner async.series() call, after the line console.log("Done all in f1").
code :


Share : facebook icon twitter icon
Invoking async.series inside async.series produces unpredictable output

Invoking async.series inside async.series produces unpredictable output


By : Spero
Date : March 29 2020, 07:55 AM
Hope that helps After about an hour of experimentation, I got it to work properly. I simply modified the firstStep function so that it takes a callback function as a parameter, and calls the callback at the end of the firstStep function.
code :
var im = require('imagemagick');
var async = require('async');

var toObtain = false;


var b;
async.series([

function (callback) {
    firstStep(callback); //the firstStep function takes a callback parameter and calls the callback when it finishes running. Now everything seems to be working as intended.
},

function (callback) {
    console.log("Starting the second step in the series");
    console.log("Value of b: " + b);
}]);


function firstStep(theCallback){
    async.series([

    function (next) { // step one - call the function that sets toObtain
        im.identify('kittens.png', function (err, features) {
            if (err) throw err;
            console.log("Invoking the function firstStep");
            toObtain = features;
            //console.log(toObtain);
            b = toObtain.height;
            next(); // invoke the callback provided by async
        });
    },

    function (next) { // step two - display it
        console.log('the value of toObtain is: %s',toObtain.toString());
        theCallback();
    }]);
}
Using node.js & async.js: series executing in the wrong order?

Using node.js & async.js: series executing in the wrong order?


By : Karel Prihoda
Date : March 29 2020, 07:55 AM
wish help you to fix your issue According to your comments, the problem is that your routes.avg method is asynchronous. This means that the method gets executed but doesn't block the program from continuing, which means that the 2nd closure in your series is being called almost immediately after the 1st one.
The problem isn't that the closures in the async.series call are being called out of order, it's that there's nothing that keeps your callback in closure 1 from being executed before routes.avg is finished.
What is wrong with my async.series

What is wrong with my async.series


By : Lee Fernie
Date : March 29 2020, 07:55 AM
With these it helps You won't get ids in your second task, but you'll get a callback as is described in docs.
You could do:
code :
async.series([
    function getLightsId(callback) {
        args = {
            path: {
                "username": "username"
            }
        };

        client.registerMethod("getLightState", "http://bridgeip/api/${username}/lights/", "GET");

        client.methods.getLightState(args, function (data, response) {
            var ids = [];
            for (key in data) {
                ids.push(key);
            }
            callback(null, ids);
        });
    },
], function (err, result) {
  var ids = result[0]
  var lightsState = new Object();
  async.each(ids, function (id) {
      getLightState(id, function (state) {
          lightsState[id] = state;
      });
  });
});
async.waterfall([
    function getLightsId(callback) {
        args = {
            path: {
                "username": "username"
            }
        };

        client.registerMethod("getLightState", "http://bridgeip/api/${username}/lights/", "GET");

        client.methods.getLightState(args, function (data, response) {
            var ids = [];
            for (key in data) {
                ids.push(key);
            }
            callback(null, ids);
        });
    },
    function getLightsState(ids, callback) {
        var lightsState = new Object();
        async.each(ids, function (id) {
            getLightState(id, function (state) {
                lightsState[id] = state;
            });
        }, function(err) { 
          callback(err, lightsState)
        });
    }
], function (err, result) {
  console.log(result);
});
Routes Guards causing wrong Route Navigation behavior

Routes Guards causing wrong Route Navigation behavior


By : Wayne Stanley
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You have mentioned pageRoute can have all subchild of app so its routing file should contain that module.
So that concept of lazy loading and guards can be properly used. I have answered this by assuming that your pageRoute module is child of App.
code :
const routes: Routes = [
  {
    path: '',
    loadChildren: './pages/pages.module#PagesModule',
    canActivate: [AuthGuardService]
  },
  { path: 'login', loadChildren: './login/login.module#LoginModule' },

];
canActivateChild(): boolean {
  if (this._authService.isAuthenticated()) {
      return true;
  }
  this._router.navigate(['/login']);
  return false;
}
const routes: Routes = [
  {
    path: '', component: PageComponent,
     children: [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', component: HomePageComponent },
  { path: 'contents', component: ContentsComponent },


     ]
  }
];
Multiple identical async pipe in Angular causing multiple http requests

Multiple identical async pipe in Angular causing multiple http requests


By : Stig Christensen
Date : March 29 2020, 07:55 AM
will be helpful for those in need Method 1
You can use shareReplay operator.
code :
import { shareReplay } from 'rxjs/operators';

values$ = source
  .pipe(
    shareReplay()
  );
ngOnInit() {
  this.values$.subscribe(values => this.values = values);
}
<app-main-chart [type]="type" 
                [name]="Name" 
                [values]="values" 
                [objectifs]="dataObjectifs">
</app-main-chart>
<div *ngIf="values$ | async as values">
  <app-main-chart [type]="type" 
                  [name]="Name" 
                  [values]="values" 
                  [objectifs]="dataObjectifs">
  </app-main-chart>
  <app-main-chart [type]="type" 
                  [name]="Name" 
                  [values]="values" 
                  [objectifs]="dataObjectifs">
  </app-main-chart>
</div>
Related Posts Related Posts :
  • How to fix "Object is possibly undefined"?
  • How can one use TensorFlow.js tf.data.generator for remote data sources since generators can't use callbacks
  • How can I unescape a string from python using javascript
  • How to add days into my date using angular pipe?
  • Keydown not firing on page loaded in <object> element
  • Refetch queries in react-native with graphql
  • How to execute functions across objects identically to executing the function itself with a this reference
  • NGRX Effect withLatestFrom Typescript error ts2345 troubleshooting
  • Make a checkbox checked if its id is present in an array
  • Remove disabled class when response code is 1 in each element javascript
  • Creating an input select in an editable form
  • How to convert string of ASCII codes to string of characters?
  • Detect system time and set css animation start time in browser
  • How can I build a dataTable, with a dropbox filter on top, calculated on backend?
  • What needs to be done to make multiple screen support for Javascript happen?
  • How to format a full year date/time
  • this.props.match.params passed into child component after authorisation
  • Highcharts: create multiple series grouped my month and year using JSON data
  • JS: Keep variable values for onclick event attached inside for loop
  • Failed prop type. Required prop types are undefined in my redux store
  • How to not import Vue in main js and store
  • Javascript make table with rows and columns given by user and change each cells colour onclick
  • How do you fix "ERROR in Path must be a string. Received undefined" in webpack4/copy-webpack-plugin
  • Protractor Fetching Email with Mail Listener: TypeError: deferred.fulfill is not a function
  • date-time picker bootstrap Tempus Dominus
  • How do I get all radio button id's via the name
  • Using d3 in for loop
  • Impact an array of objects
  • JS split string and return index of each split
  • Javascript/JS - Referring to classes and variables dynamically within a change event loop
  • Query a specific GET field?
  • Mapping multiple form inputs of the same name into a JavaScript object
  • How can I not to return a field from object in JavaScript?
  • Creating and testing a single Javascript nested function
  • Formatting server side jQuery Datatable
  • How to show tooltips onmouseover in p:calendar
  • typescript - calling function at random intervals in ionic
  • Correct way to populate an array from a promise
  • JavaScript Mini-Max Sum - Returns 0
  • canvas not clearing while radius of circle decreasing..?
  • Dynamically Growing Dropdown Component with clickoutside directive
  • MultichoiceField in ModelForm for Django with DB relations
  • React Native "if" statement behaviour? Early exit or full evaluation?
  • Call Jquery function on Input tag having data-slider
  • How to process negative shifts in Caesars Cipher (Javascript)
  • Animating Line position in Konva
  • Why a state is not resolved as a variable in nextjs
  • How to efficiently evaluate element in javascript array by using reduce function
  • Google script web app goes blank page after submit
  • Event for the load-end of dynamically added CSS files through innerHTML
  • How to retrieve some text from a sibling div element in jQuery
  • How to display half star rating in my following custom angular star rating example?
  • Angular 8: ternary operation for img src attribute?
  • Is this proper JS for this J-Query expanding textArea? Is 'this' the same as event.target in JS also?
  • How to fix user fetching from a collection in discord.js?
  • Can I create an item id when adding it to a collection?
  • Temporarily disable a specific option after it has been selected (in any selector) for all instances of that selector in
  • Vis.js timeline item align property not working
  • How to select one element instead of all elements using 'clicked' in a Django for loop
  • How to check if 2 <img> tags contain the same image
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org