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

Implemented tasklets.synctasklet #58

Merged
merged 2 commits into from
May 18, 2019
Merged

Conversation

michaelawyu
Copy link
Contributor

No description provided.

@michaelawyu michaelawyu requested review from crwilcox and andrewsg April 2, 2019 23:10
@chrisrossi chrisrossi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 3, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 3, 2019
Copy link
Contributor

@chrisrossi chrisrossi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Luckily, the code itself is fairly straightforward and looks perfect. My only suggestions revolve around communicating what it is better.

def synctasklet(*args, **kwargs):
raise NotImplementedError
def synctasklet(wrapped):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I prefer this style, with the first line of text on its own line, the Google style guide wants for there to be no newline between the triple quote and the first line of text: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html

raise NotImplementedError
def synctasklet(wrapped):
"""
A decorator to run a function as a tasklet when called.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A shortcoming of the original code, in my opinion, is that it's not clear what this actually does from the docstring. I stared at this a while trying to figure out how it was supposed to be used and finally grokked it when I read the narrative documentation.

It seems to me, now, that this docstring is actually inverted from the truth: It's a decorator to run a tasklet as a function. In other words, the point is to decorate a function written like a tasklet, with yield, so it can be run in a synchronous context. It's a tasklet, but rather than returning a future the way a standard tasklet would, it returns the future's result, effectively converting it to a synchronous call, with any asynchronous calls made internally still being able to potentially run in parallel.

It would be great if the docstring could reflect the reality a little better, so the next developer isn't scratching their head the way I was.

with pytest.raises(NotImplementedError):
tasklets.synctasklet()
@tasklets.synctasklet
def regular_function(value):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the new understanding above, maybe this should be a generator function with a yield, so we can test the intended use case.

@chrisrossi
Copy link
Contributor

Also, it's not clear to me why the Kokoro build is failing, here, but it's failing in the docs step. Try nox -e docs, locally, to see if that gives you any more insight. We'll need the build to pass as well, naturally.

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 29, 2019
@cguardia
Copy link
Contributor

@michaelawyu Anything we can do to help get this PR to the finish line? We are thankful for the help, and would like to see this getting merged.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 17, 2019
@michaelawyu
Copy link
Contributor Author

@michaelawyu Anything we can do to help get this PR to the finish line? We are thankful for the help, and would like to see this getting merged.

Many apologies for the very late response; I had some health issues recently and didn't get to respond. I have made the requested changes, PTAL.

Copy link
Contributor

@cguardia cguardia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much! I hope your health is better now. Take care.

@cguardia cguardia merged commit 6bdef13 into master May 18, 2019
@michaelawyu michaelawyu deleted the michaelawyu-patch-synctasklet branch May 24, 2019 00:52
@yoshi-automation yoshi-automation removed 🚨 This issue needs some love. 🚨 labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants