Angular 6 best way to sequence functions that are not http oriented

John M.

I am not strong with RxJS so am looking for guidance on how best to chain a sequence of simple non http.get etc. functions in Angular so that they happen in a synchronous fashion.

E.g. what is the 'best' way to run these in sequence in a component?

  function1() {
    setTimeout(function(){ alert("Hello 1"); }, 3000);
  }

  function2() {
    setTimeout(function(){ alert("Hello 2"); }, 6000);
  }

  function3() {
    setTimeout(function(){ alert("Hello 3"); }, 1000);
  }

  function4() {
    setTimeout(function(){ alert("Hello 4"); }, 750);
  }
Sunil Singh

If you have async call, you can look for forkJoin from rxjs.

Here is the sample demo - https://stackblitz.com/edit/typescript-bqxg9x

Reference - https://www.learnrxjs.io/operators/combination/forkjoin.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Best way for multiple HTTP Request in Angular

Best way to parse this sequence?

What is the best way to sum arrays using ECMASCRIPT 6 Generator/Functions

best way to write code of bool that check 6 functions?

Angular6 how to test a sequence of http requests

How to make a sequence of http requests in Angular 6 using RxJS

Best way to use javascript promise chaining in order to have truly asynchronous sequence of functions?

What is the best way to integrate angular 6 in asp .net mvc?

What is the best way to use observables for http requests in angular?

What is the best way to implement sequencial http requests with optimistic concurrency in angular?

Best way to call functions asynchronously

XQuery: best way to convert node sequence to array

Best way to resize a data sequence in Python

The best way to execute a sequence once in C++

Best way to test HTTP queries

Angular 6 and Firestore: best way to loop through and update each Document in AFS Collection?

Best way to display a json object in a json object in Angular 2 release 6

Best way to integrate NodeJS with Angular

Best Way For Token Validation in Angular

Best way to switch classes in Angular

Best way to register event in Angular

Http Client Angular 6

Best way to structure helpers functions in NodeJS

Best way to pass nullable values to functions

What is the best way to wrap synchronous functions in to a promise

Best way to document anonymous objects and functions with jsdoc

Python, best way to override functions for optimization

ClaiR/Rascal: Best way to list public functions?

Best way to organize javascript functions and files?