You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* updates to dependencies to get working locally?
* Try to improve afterSave documentation to include:
1. How to ensure that afterSave runs async if necessary
2. That request.context is a feature and how to use it.
I also added a real world code example that uses modern javascript.
The client will receive a successful response to the save request after the handler terminates, regardless of how it terminates. For instance, the client will receive a successful response even if the handler throws an exception. Any errors that occurred while running the handler can be found in the Cloud Code log.
242
+
## Async Behavior
243
243
244
+
In the example above, the client will receive a successful response before the promise in the handler completes, regardless of how the promise resolves. For instance, the client will receive a successful response even if the handler throws an exception. Any errors that occurred while running the handler can be found in the Cloud Code log.
245
+
246
+
You can use an `afterSave` handler to perform lengthy operations after sending a response back to the client. In order to respond to the client before the `afterSave` handler completes, your handler may not return a promise and your `afterSave` handler may not use async/await.
247
+
248
+
## Using Request Context
249
+
250
+
State can be passed from a `beforeSave` handler to an `afterSave` handler in the Reqeuest Context. The following example sends emails to users who are being added to a [Parse.Role's users relation](https://parseplatform.org/Parse-SDK-JS/api/2.1.0/Parse.Role.html#getUsers) asynchronously, so the client receives a response before the emails complete sending:
251
+
252
+
```javascript
253
+
constbeforeSave=functionbeforeSave(request) {
254
+
const { object:role } = request;
255
+
// Get users that will be added to the users relation.
256
+
constusersOp=role.op('users');
257
+
if (usersOp &&usersOp.relationsToAdd.length>0) {
258
+
// add the users being added to the request context
If you want to use `afterSave` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself.
0 commit comments