-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make “transforms” more flexible by allowing async behavior #31
Comments
Hey Andrew,
I 100% agree with this and would welcome a PR.
There's definitely a way to do this without binding us to connect's signature, but I'm not sure I understand the value. I guess it would let the user skip the remaining transforms and respond with a success message earlier. Is there a use case for that? (Note: the user can already skip the remaining steps and jump straight to responding by throwing an error in a transform—or, when we implement your suggestion above, by returning a promise that gets rejected.) |
Yeah, and moreover, it would remove the need for named hooks like Can you give some guidance on where to add tests for this? Maybe in the create-resource integration tests? |
I’d like to use the
beforeSave
function not so much as a transformation, but as a place to do some asynchronous work, and have the ability to carry out or cancel the save based on the results of the async task.For example, the specific case I have right now is a resource that represents a file in an S3 bucket: I want to perform an upload to S3, which upon succeeding, will continue to save to Mongo. If the bucket upload fails, though, I want to be able to
reject
or something and kick off an error response.A related thought that I’ve been thinking for some time is that maybe it would be worth exploring making each of these steps a distinct middleware. Although, that would be a function signature specific to Connect and Express servers, so maybe that doesn’t jive with the project’s vision. At any rate, I think these transforms could detect whether a Promise is being returned, and wait for it to settle if needed.
What do you think, @ethanresnick?
The text was updated successfully, but these errors were encountered: