Q:

Calling a promise multiple times with delay Bluebird.js

Right now I have
getUserInfo = (data) => {
    console.log('Getting user info')
    return new Promise((resolve, reject) => {
        if (data === 1)
        return resolve('Hello World')
        resolve(getUserInfo(1))
    })
}

getUserInfo().then(data => console.log(data))

This will console.log

Getting user info
Getting user info
Hello World

That's exactly what I want, calling a promise multiple times and then resolve. 
However I want to add a delay between promises so I would like to have:

Getting user Info
Wait 1 second
Getting user Info
Hello World

I want to use Promise.delay from bluebird. Any tip on how to go? 
I've tried
getUserInfo = (data) => {
    console.log('Getting user info')
    return new Promise.delay(500,(resolve, reject) => {
        if (data === 1)
        return resolve('Hello World')
        resolve(getUserInfo(1))
    })
}

But as resolve data of the promise this returns Function:

Getting user info
[Function]

Thank you in advance!

A:

Delay is a promise, not a promise constructor.  So you can use Promise.delay like any other promise..
Below is maybe what your after ->

const getUserInfo = (data) => {
    console.log('Getting user info')
    return new Promise((resolve, reject) => {
        if (data === 1) {
          return resolve('Hello World')
        }
        return Promise.delay(500).then(
           function ()  { resolve(getUserInfo(1)); }
        );
    })
}

getUserInfo().then(data => console.log(data))
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.5.1/bluebird.min.js"></script>

Using new async / await, can make things like this much easier.

const getUserInfo =  async (data) => {
    console.log('Getting user info')
    if (data === 1) return "hello World";
    await Promise.delay(500);
    return getUserInfo(1);
}

getUserInfo().then(data => console.log(data))
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.5.1/bluebird.min.js"></script>

