Outsource the result set synchronization logic.

The existing logic can't run until all results have been parsed delaying
the presentation of any results for large data sets, and may suffer from
buffer overruns in some rare cases.  Replace it with some template code
from nemo that performs the same function but can be run in batches and
has good track record of stability.

Change-Id: I396988be910c89a80a1353cbd37529fd15bfb7ce
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>