Skip to content
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

feat: support async recipes #305

Closed
wants to merge 4 commits into from
Closed

Conversation

aleclarson
Copy link
Member

@aleclarson aleclarson commented Jan 30, 2019

Drafts won't be revoked until the returned promise is fulfilled or rejected.

The readme needs to be updated to reflect this. Anyone willing to contribute here?

As suggested by @Yurickh in #302 (comment)

@aleclarson
Copy link
Member Author

I've added tests for the two basic cases:

  • modifying the draft before and after the recipe function has returned
  • awaiting a rejected promise

If anyone has more test ideas, please speak up!

@coveralls
Copy link

coveralls commented Jan 30, 2019

Coverage Status

Coverage increased (+0.02%) to 99.714% when pulling 5a99c88 on aleclarson:promise into 271cd1b on mweststrate:master.

@mweststrate
Copy link
Collaborator

Great stuff! Will review in details next week, but the Promise support is an extremely useful feature! I can update the typings and docs as well. I might add a bit of refactoring on top of this, to also expose the lower level api as proposed in #302,

  • docs
  • typings
  • low level api

P.S.: you do have the permissions to directly create branches on this repository, which makes it possible to both commit to the same branch :)

@aleclarson
Copy link
Member Author

P.S.: you do have the permissions to directly create branches on this repository, which makes it possible to both commit to the same branch :)

True! I would do that, but I would need to reopen this PR. Note that "Allow edits from maintainers" is enabled! ;)

@mweststrate
Copy link
Collaborator

questions that just popped up in my mind: does this affect isDraft / original / recursive produce calls if they are invoked after the first await?

@aleclarson
Copy link
Member Author

aleclarson commented Jan 31, 2019

Definitely not for isDraft and original, but we do need tests for recursive produce calls after await.

@aleclarson
Copy link
Member Author

aleclarson commented Jan 31, 2019

For recursive use after await, one bug is that the nested produce call will return an auto-frozen copy even when it contains a draft owned by another produce call.

During the finalize phase, we need to track how many unowned drafts will exist in the returned copy. We would only be able to auto-freeze the result if no unowned drafts are found.

edit: Working on a fix for this..

@aleclarson
Copy link
Member Author

Note: With async recipe functions, it remains unsafe to "hoist" drafts out of the recipe, since they can be revoked at any time.

@mweststrate
Copy link
Collaborator

mweststrate commented Jan 31, 2019 via email

@aleclarson
Copy link
Member Author

aleclarson commented Jan 31, 2019

as finalizing would always happen on at least one tick later; when the promise settles

I don't think so, because you're not required to use promises when deferring the finalize phase. I've separated that logic into the processResult method.

@mweststrate
Copy link
Collaborator

ah, that is awesome @aleclarson!

@aleclarson
Copy link
Member Author

Note: With the current implementation, you wouldn't be able to call finishDraft more than once on any draft related to a single createDraft call, because they all share the same ImmerScope instance.

@aleclarson
Copy link
Member Author

The issue mentioned in #305 (comment) has been fixed. 🎉

@aleclarson
Copy link
Member Author

aleclarson commented Jan 31, 2019

Note: With e280946, unowned drafts will only prevent auto-freezing of affected "branches". Branches which contain no unowned drafts will be safely auto-frozen! 👍

Previously, a nested produce call would never auto-freeze anything in its result.

@aleclarson
Copy link
Member Author

@mweststrate Node 6 doesn't support async/await, so the tests are failing. Maybe we should drop Node 6 support? :P

@Yurickh
Copy link

Yurickh commented Jan 31, 2019

@mweststrate Node 6 doesn't support async/await, so the tests are failing. Maybe we should drop Node 6 support? :P

THAT would be a breaking change after all haha

@aleclarson
Copy link
Member Author

@Yurickh Yup! 😆 I decided against that silly idea.

We can revert 5a99c88 when the time comes!

@mweststrate mweststrate mentioned this pull request Feb 2, 2019
4 tasks
@mweststrate
Copy link
Collaborator

Closed MR in favor of #307 (which is the same, but on this repo)

@mweststrate mweststrate closed this Feb 2, 2019
@aleclarson
Copy link
Member Author

@mweststrate Were you having trouble editing this PR? Or just want to avoid adding another git remote?

@mweststrate
Copy link
Collaborator

mweststrate commented Feb 2, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants