-1

I'm trying to trigger 3 functions one after another. When each completes, next starts my code :-

getInfo(f1 , f2).then(function() {
    setInfo().then(function(callback) {
        Three();
    });
});

i get this error :-

>TypeError: Cannot read property 'then' of undefined

Update

function setInfo(){  

    alert('done')   

  } 
5
  • 1
    or either getInfo or setInfo (or both!) are not defined in the scope you trying to access it. Try to share a little bit more of code to us to see what is the issue. Commented Jun 8, 2018 at 17:43
  • need to know more about setInfo() Commented Jun 8, 2018 at 17:44
  • What does getInfo() return? What does setInfo() return? Why aren't you returning from within either then callback to continue the chain? Commented Jun 8, 2018 at 17:46
  • 2
    The functions getInfo and setInfo must return a Promise Commented Jun 8, 2018 at 17:48
  • 1
    What are you actually trying to do? alert is blocking and doesn't return a Promise. You can't call then() on something that doesn't have a then() method. Commented Jun 8, 2018 at 18:02

1 Answer 1

2

You need to actually chain.

Let's assume your code has an API similar to below. getInfo, setInfo, and maybe Three are all asynchronous. They return Promises that resolve to some value.

function getInfo(a, b) {
  return Promise.resolve(true);
}

function setInfo() {
  alert("done");
  return Promise.resolve(true);
}

function Three() {
  return Promise.resolve(true);
}

You need to actually chain them together so they all wait on one another and propagate up values.

const f1 = "foo";
const f2 = "bar";

getInfo(f1, f2)
  .then(() => setInfo())
  .then(cb => Three());
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.