0

Is it possible to call one first service and another?

I have two services, below are the details:

dataservice.getCPUUtilization(model.dbName).then(function (data) {
  model.cpuUtilizationChart = data;
  model.cpuPercentage = model.cpuUtilizationChart[0].combined;
  console.log ("******** CPU Utilization Chart components are ******* :" + model.cpuUtilizationChart);
  console.log ("******** CPU Percentage is ******* :" + model.cpuPercentage);                       
});
 dataservice.setCPUPercentage(model.setcpuPercentage);

After the getCPUUtilization service I need to call: But it is calling setCPUPercentage first and the getCPUUtilization?

1
  • 1
    Please add more code - where is dataservice.setCPUPercentage & dataservice.getCPUUtilization used ? Now you are pasting seperate code blocks... Commented Jul 20, 2016 at 9:41

2 Answers 2

1

More code should help, but i believe that these calls your're performing are async.

Making two calls in two consecutive lines of code doesn't that the last one will run right after the other ends.

You need to make the second call in the callback of the first one, that's the only way to ensure the first call is completed before making the second.

Try this:

dataservice.getCPUUtilization(model.dbName).then(function (data) {
    model.cpuUtilizationChart = data;
    model.cpuPercentage = model.cpuUtilizationChart[0].combined;
    console.log ("******** CPU Utilization Chart components are ******* :" + model.cpuUtilizationChart);
    console.log ("******** CPU Percentage is ******* :" + model.cpuPercentage);

    //Now in the callback
    dataservice.setCPUPercentage(model.setcpuPercentage);
});
Sign up to request clarification or add additional context in comments.

Comments

0
 dataservice.getCPUUtilization(model.dbName).then(function (data) {
  model.cpuUtilizationChart = data;
  model.cpuPercentage = model.cpuUtilizationChart[0].combined;
  console.log ("******** CPU Utilization Chart components are ******* :" + model.cpuUtilizationChart);
  console.log ("******** CPU Percentage is ******* :" + model.cpuPercentage);                       
}, function(){
 dataservice.setCPUPercentage(model.setcpuPercentage);
);

This would solve your problem.

1 Comment

How? You're binding a rejection callback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.