Skip to content

Conversation

@oerling
Copy link
Contributor

@oerling oerling commented Jan 20, 2022

AsyncSource encapsulates a background computation. These can be
scheduled on a background executor. The difference between this and a
future is that when the user requires the result, AsyncSource will
perform the async peration on the caller's thread and will turn the
background operation into a no-op.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 20, 2022
@facebook-github-bot
Copy link
Contributor

@oerling has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@pedroerp pedroerp left a comment

Choose a reason for hiding this comment

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

Nice, code looks pretty clean and easy to understand :) A few minor API and test comments:

// will either wait for the make to finish or run the make on its
// own thread.
bool isPending() const {
return make_ && !item_;
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this test making_ instead of make_? For instance, this will return true if the object was just constructed but before prepare() was called, which sounds a bit counter-intuitive at a first look at the API. Is that the intended behavior?

// Returns the item to the first caller and nullptr to subsequent callers. If
// the item is preparing on the executor, waits for the item and otherwise
// makes it on the caller thread.
std::unique_ptr<Item> move() {
Copy link
Contributor

Choose a reason for hiding this comment

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

another way to implement this method (in a truly async way), is making it return a Future instead of blocking internally. The client of this API could then decide whether to block or propagate that future. Internally you would have to hold a SharedPromise instead of a Promise

if (make) {
return make();
}
auto& exec = folly::QueuedImmediateExecutor::instance();
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the part where ideally you would return the semi future so that the client could attach their preferred executor, instead of blocking the current thread.

int32_t id;
};

TEST(AsyncSourceTest, basic) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect the "basic" test to test the basic API, like construct a single async source, check isPending() and hasValue(), then call prepare(), check the method return the expected results again, then move the results out, etc.

Then having the test below as a "multi-thread" test that checks for concurrent behavior.

@oerling
Copy link
Contributor Author

oerling commented Jan 25, 2022 via email

Copy link
Contributor

@pedroerp pedroerp left a comment

Choose a reason for hiding this comment

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

Thanks for replying to the comments and for the tests. Looks good!

AsyncSource encapsulates a background computation. These can be
scheduled on a background executor. The difference between this and a
future is that when the user requires the result, AsyncSource will
perform the async peration on the caller's thread and will turn the
background operation into a no-op.
@facebook-github-bot
Copy link
Contributor

@oerling has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

rui-mo pushed a commit to rui-mo/velox that referenced this pull request Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants