Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

View#fetch_all - async method for fetching all records

Change-Id: Id42af81ca4e2748e3fe7588c2a87bbf8d1aea76f
Reviewed-on: http://review.couchbase.org/24027
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information...
commit c4b364203dfd11df6fdef922e41dca02d7f11cf0 1 parent 48538aa
@funny-falcon funny-falcon authored avsej committed
Showing with 32 additions and 0 deletions.
  1. +8 −0 RELEASE_NOTES.markdown
  2. +24 −0 lib/couchbase/view.rb
View
8 RELEASE_NOTES.markdown
@@ -14,6 +14,14 @@ bugfixes. Do not forget to update this doc in every important patch.
* [major] RCBC-118 Alias #total_rows as #total_entries on view result
set to match documentation.
+* [minor] View#fetch_all - async method for fetching all records
+
+ conn.run do
+ doc.recent_posts.fetch_all do |posts|
+ do_something_with_all_posts(posts)
+ end
+ end
+
## 1.2.1 (2012-12-28)
* [major] RCBC-101 Persistence constraints wasn't passed to mutation
View
24 lib/couchbase/view.rb
@@ -374,6 +374,30 @@ def fetch(params = {}, &block)
end
end
+ # Method for fetching asynchronously all rows and passing array to callback
+ #
+ # Parameters are same as for {View#fetch} method, but callback is called for whole set for
+ # rows instead of one by each.
+ #
+ # @example
+ # con.run do
+ # doc.recent_posts.fetch_all do |posts|
+ # do_something_with_all_posts(posts)
+ # end
+ # end
+ def fetch_all(params = {}, &block)
+ return fetch(params) unless @bucket.async?
+ raise ArgumentError, "Block needed for fetch_all in async mode" unless block
+
+ all = []
+ fetch(params) do |row|
+ all << row
+ if row.last?
+ @bucket.create_timer(0) { block.call(all) }
+ end
+ end
+ end
+
# Returns a string containing a human-readable representation of the {View}
#
Please sign in to comment.
Something went wrong with that request. Please try again.