Promise can't return msg

I am trying to use a function with the following seems to be simple code.

settings.js

    functionGlobalContext: {
        bluebird:require('bluebird')
    },

function

const Promise = context.global.bluebird

const p = new Promise((resolve, reject) => {
    setTimeout(()=>{
        resolve(10)
    }),1000
})

p.then(number => {
    msg.topic = number
    node.warn(msg.topic)
    return msg
})

and can't return the msg object. In addition, I still did not understand how to properly connect external modules through the setup tab of the function block.

Hello Root,

const bluebird = global.get("bluebird")  // reference library

const p = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(10)
    }, 1000)
})

p.then(number => {
    msg.topic = "My promise number"
    msg.payload = number
    //node.warn(msg.topic)
    node.send(msg)
})
  1. you were referencing the library wrong (Documentation)
  2. you had the ms timeout outside the brackets
  3. dont know what the library does .. thats up to you :wink:
1 Like

thank you very much.
Truly, asynchronous need to be returned via node.send(msg) :relaxed:

Do not use bluebird. There is no good reason for using that library these days. All supported versions of node.js have full support for Promise built in.

1 Like

I'm just studying the tool I'm trying to work with. I am reading this wonderful forum and I am asking questions that are incomprehensible to me. But first, in order not to distract the community, I try to figure it out on my own. I think many people do this. Although the above example was simple, it still allowed me to go further. Thank you sincerely for your wonderful knowledge.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.