Backendless Support
 
Solved

Promises for Backendless 4.0+

Hi how to enable promises for custom business logic written in JS. According to Docs it should work like in old version:

Backendless.enablePromises();But when I do this I receive error of:Backendless.enablePromises is not a function (undefined:30:13)

Leave a Comment

Comments (3)

photo
2

Tomas,

In version 4 promises are enabled automatically. In fact, all non-blocking APIs automatically return a Promise object:

https://backendless.com/docs/js/doc.html#sync_and_async_calls

Regards,

Mark

photo
1

Thank you, just to let u know - when u navigate to backendless documentation:

https://backendless.com/products/documentation/

And open NodeJS guide for v 4.0

https://backendless.com/docs/bl-js/doc.html

You can find this information:

  1. Enabling promises in Backendless API, then returning result of the Backendless Data Service "save" method - which will be a promise, since the promises are enabled:

    backendless-promises-approach.js

    1234567891011121314Backendless.enablePromises();Backendless.ServerCode.Persistence.afterCreate('Comment', function (req) { var PostsStore = Backendless.Data.of('Post'); return PostsStore.findById(req.item.post) .then(post => { post.comments++; return PostsStore.save(post); }) .catch(err => { return Promise.reject('Unable to update post comments counter. Got an error : ' + err.message) });}, true)

photo
1

Thanks for pointing it out. We will get that fixed.