willowtreeapps / wombats-lambda

0 stars 1 forks source link

Allow for promise events (javascript) #8

Open ghost opened 7 years ago

ghost commented 7 years ago

BEFORE SUBMITTING AN ISSUE CHECK THE FOLLOWING:

FEATURE REQUEST

- Describe the feature you would like to see Would be neat to support promises so we can use async logic in our events. - Why you need it See comments below - How it should work Something like this:

 exports.handler = (event, context, callback) => {
     // This is used to know how much time you have left for your code
     const time_left = context.getRemainingTimeInMillis;

-    callback(null, handleEvent(event, time_left));

+    Promise.resolve(handleEvent(event, time_left)).then(result =>
+        callback(null, result));

 };
dehli commented 7 years ago

What are you thinking would be your use case for async logic? Also in regards to testing, it's kinda tough right now (but we're going to improve how that works).

ghost commented 7 years ago

Some thoughts:

I suppose... JavaScript at heart is async, and restricting it to sync doesn't feel free.

dehli commented 7 years ago

Totally agree! We're going to most likely pass a callback function to your bot. Will update this issue once we add it!