NAME
Couchbase::OpContext - Operation context
SYNOPSIS
my $ctx = $bucket->batch();
# Create a bunch of documents
my @docs = map { Couchbase::Document->new($_, {name=>$_}) } (qw(foo bar baz));
$ctx->upsert($_) for @docs;
$ctx->wait_all();
# Get them back, reading each result as it arrives
$ctx = $bucket->batch();
$ctx->get($_) for @docs;
while ((my $cur = $ctx->wait_one)) {
printf("Got document ID %s with name %s\n", $doc->id, $doc->value->{name});
}
DESCRIPTION
The OpContext
class is used to schedule multiple operations and send them over the network as a single group.
To schedule operations on the context object, simply invoke the requested operation as a method of the context object itself (rather than the bucket).
Once all the operations have been scheduled, the results should be submitted to the cluster and waited for.
Once all operations have been completed, the batch object is no longer valid and must be recreated using the batch()
method on Couchbase::Bucket.
wait_all()
Waits for all the scheduled operations to complete. When this method returns, all documents passed to the operations will have completed and their contents will be updated with new data from the server.
wait_one()
Waits for the next scheduled operation to complete. This method is an alternative to waiting for all the operations to complete. This allows your application to deal with each response as it arrives, rather than waiting for them all to complete.
This method returns the next document whose operation has been completed, and a false value when no more outstanding operations remain.