refactor receive() code out of query() so it can be used with notifications

Summary:
this is a change to upstream third-party source, and should
be submitted for inclusion.

Test Plan: I have an application which uses this, and it works.

Reviewers: sid0, wez

Reviewed By: wez

Differential Revision: https://reviews.facebook.net/D28641