Skip to content
Advertisement

How to fetch value from Promise object after promise has been resolved

Please note This is a contrived example.

JavaScript

Problem

I am unable to figure out how to return any kind of object/function for further downstream processing after shortAfterLongFunc completes. I can console.log from shortAfterLongFunc but that’s not what i require here. Fiddle Here

Thanks for looking!

UPDATE:

Okay just to make my question slightly better…this is a simple use case I am looking at:

JavaScript

somefunc() lets say processes each element of Array to lower case. However, assume this processing takes a long time and async (think setTimeout).. hence a promise to ensure synchronous operation for each element…but on using promise I find myself not able return the transformed value

Advertisement

Answer

Just chain another then call, since shortAfterLongFunc returns new promise you can further work with it:

JavaScript

Demo: http://jsfiddle.net/ebt4pxxa/2/

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement