Expand my Community achievements bar.

SOLVED

Example of returning a promise in a custom code action?

Avatar

Community Advisor

Hi everyone, looking for some help!

 

This Adobe blog post states "If your Custom Code is JavaScript, then you can now return a promise in conditions or actions. The next condition or action will wait for the promise to resolve before executing."

 

I'm struggling to figure out how to do this.  Has anyone got a simple JavaScript code example they could share? (i.e. return a promise in an action so that the following action waits)

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Here's something you can try 

 

// action1    
return new Promise(function(resolve, reject) { setTimeout(function() { var thankGodItIsFriday = (new Date().getDay() === 5) if (thankGodItIsFriday) { resolve(); } else { reject(); } }, 1000); }); }

Editing to add article reference: 

Here's a good read around async and an example as well. 

https://www.datanalyst.info/web_analytics/adobe-launch/launch-async-sequential/

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Here's something you can try 

 

// action1    
return new Promise(function(resolve, reject) { setTimeout(function() { var thankGodItIsFriday = (new Date().getDay() === 5) if (thankGodItIsFriday) { resolve(); } else { reject(); } }, 1000); }); }

Editing to add article reference: 

Here's a good read around async and an example as well. 

https://www.datanalyst.info/web_analytics/adobe-launch/launch-async-sequential/