0

I'm trying to deal with promise as described by Vibrant.js while formatting the response. It should return

When I output the response to the console with the following code it works fine.

function main(imageURL) {
  Vibrant.from(imageURL).getPalette()
    .then((palette) => console.log(palette))
}

However, I want to format the response through another function. So I have the following but the console does not long anything.

function main(imageURL) {
  Vibrant.from(imageURL).getPalette()
    .then((palette) => formattedPalette(palette))
}

function formattedPalette(palette) {
  return palette
}

main();
console.log(main())

I'm obviously missing something while chaining events.

olimart
  • 1,529
  • 3
  • 17
  • 32
  • 1
    `console.log(main())` but `main` does not return anything... you'll have to return the `Promise` and use the same sort of `.then` chaining after calling `main` – CertainPerformance Oct 18 '18 at 23:49
  • Specifically: `return Vibrant.from(...)...;`, and `main().then(p => console.log(p))`. – deceze Oct 18 '18 at 23:51
  • Still not getting it. `formattedPalette` returns the value. What prevents `main` from logging it? I want `main` to return the value so when I call `console.log(main())` I get the result. – olimart Oct 19 '18 at 01:01
  • `formattedPalette` returns the value *to the `then` callback*. Where does `main` `return` anything? It doesn’t. It’s all happening in callbacks which you have no access to from outside, unless you return the promise chain. – deceze Oct 19 '18 at 03:59

0 Answers0