Skip to content

Commit ee4b396

Browse files
streamrouter: document methods to instruct user on how to exit early
1 parent 393b476 commit ee4b396

File tree

8 files changed

+110
-12
lines changed

8 files changed

+110
-12
lines changed

lib/bigquery/index.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,14 @@ BigQuery.prototype.dataset = function(id) {
168168
* @param {function} callback - The callback function.
169169
*
170170
* @example
171-
* bigquery.getDatasets(function(err, datasets, nextQuery, apiResponse) {
172-
* // If `nextQuery` is non-null, there are more results to fetch.
173-
* });
171+
* var callback = function(err, datasets, nextQuery, apiResponse) {
172+
* if (nextQuery) {
173+
* // More results exist.
174+
* bigquery.getDatasets(nextQuery, callback);
175+
* }
176+
* };
177+
*
178+
* bigquery.getDatasets(callback);
174179
*
175180
* //-
176181
* // Get the datasets from your project as a readable object stream.
@@ -183,6 +188,15 @@ BigQuery.prototype.dataset = function(id) {
183188
* .on('end', function() {
184189
* // All datasets retrieved.
185190
* });
191+
*
192+
* //-
193+
* // If you anticipate many results, you can end a stream early to prevent
194+
* // unnecessary processing and API requests.
195+
* //-
196+
* bigquery.getDatasets()
197+
* .on('data', function(dataset) {
198+
* this.end();
199+
* });
186200
*/
187201
BigQuery.prototype.getDatasets = function(query, callback) {
188202
var that = this;
@@ -250,6 +264,15 @@ BigQuery.prototype.getDatasets = function(query, callback) {
250264
* .on('end', function() {
251265
* // All jobs retrieved.
252266
* });
267+
*
268+
* //-
269+
* // If you anticipate many results, you can end a stream early to prevent
270+
* // unnecessary processing and API requests.
271+
* //-
272+
* bigquery.getJobs()
273+
* .on('data', function(job) {
274+
* this.end();
275+
* });
253276
*/
254277
BigQuery.prototype.getJobs = function(options, callback) {
255278
var that = this;
@@ -330,14 +353,15 @@ BigQuery.prototype.job = function(id) {
330353
* //-
331354
* // You can run a query against your data in a serial manner.
332355
* //-
333-
* bigquery.query(query, function(err, rows, nextQuery, apiResponse) {
356+
* var callback = function(err, rows, nextQuery, apiResponse) {
334357
* // Handle results here.
358+
*
335359
* if (nextQuery) {
336-
* bigquery.query(nextQuery, function(err, rows, nextQuery, apiResponse) {
337-
* // Handle more results here.
338-
* });
360+
* bigquery.query(nextQuery, callback);
339361
* }
340-
* });
362+
* };
363+
*
364+
* bigquery.query(query, callback);
341365
*
342366
* //-
343367
* // You can also use the `query` method as a readable object stream by

lib/bigquery/table.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,14 @@ Table.prototype.getMetadata = function(callback) {
491491
* maxResults: 100
492492
* };
493493
*
494-
* table.getRows(options, function(err, rows, nextQuery, apiResponse) {
495-
* // If `nextQuery` is non-null, there are more results to fetch.
494+
* var callback = function(err, rows, nextQuery, apiResponse) {
496495
* if (nextQuery) {
497-
* table.getRows(nextQuery, function(err, rows, nextQuery, apiResponse) {});
496+
* // More results exist.
497+
* table.getRows(nextQuery, callback);
498498
* }
499-
* });
499+
* };
500+
*
501+
* table.getRows(options, callback);
500502
*
501503
* //-
502504
* // Get the rows as a readable object stream.
@@ -507,6 +509,15 @@ Table.prototype.getMetadata = function(callback) {
507509
* .on('end', function() {
508510
* // All rows have been retrieved.
509511
* });
512+
*
513+
* //-
514+
* // If you anticipate many results, you can end a stream early to prevent
515+
* // unnecessary processing and API requests.
516+
* //-
517+
* table.getRows()
518+
* .on('data', function(row) {
519+
* this.end();
520+
* });
510521
*/
511522
Table.prototype.getRows = function(options, callback) {
512523
var that = this;

lib/pubsub/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ function PubSub(options) {
139139
* .on('end', function() {
140140
* // All topics retrieved.
141141
* });
142+
*
143+
* //-
144+
* // If you anticipate many results, you can end a stream early to prevent
145+
* // unnecessary processing and API requests.
146+
* //-
147+
* pubsub.getTopics()
148+
* .on('data', function(topic) {
149+
* this.end();
150+
* });
142151
*/
143152
PubSub.prototype.getTopics = function(query, callback) {
144153
var self = this;
@@ -440,6 +449,15 @@ PubSub.prototype.topic = function(name, options) {
440449
* .on('end', function() {
441450
* // All subscriptions retrieved.
442451
* });
452+
*
453+
* //-
454+
* // If you anticipate many results, you can end a stream early to prevent
455+
* // unnecessary processing and API requests.
456+
* //-
457+
* pubsub.getSubscriptions()
458+
* .on('data', function(topic) {
459+
* this.end();
460+
* });
443461
*/
444462
PubSub.prototype.getSubscriptions = function(options, callback) {
445463
var self = this;

lib/pubsub/topic.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ Topic.prototype.delete = function(callback) {
218218
* .on('end', function() {
219219
* // All subscriptions retrieved.
220220
* });
221+
*
222+
* //-
223+
* // If you anticipate many results, you can end a stream early to prevent
224+
* // unnecessary processing and API requests.
225+
* //-
226+
* topic.getSubscriptions()
227+
* .on('data', function(subscription) {
228+
* this.end();
229+
* });
221230
*/
222231
Topic.prototype.getSubscriptions = function(options, callback) {
223232
if (util.is(options, 'function')) {

lib/search/index-class.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ Index.prototype.document = function(id) {
190190
* .on('end', function() {
191191
* // All documents retrieved.
192192
* });
193+
*
194+
* //-
195+
* // If you anticipate many results, you can end a stream early to prevent
196+
* // unnecessary processing and API requests.
197+
* //-
198+
* index.getDocuments()
199+
* .on('data', function(document) {
200+
* this.end();
201+
* });
193202
*/
194203
Index.prototype.getDocuments = function(query, callback) {
195204
var self = this;

lib/search/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ function Search(options) {
138138
* .on('end', function() {
139139
* // All indexes retrieved.
140140
* });
141+
*
142+
* //-
143+
* // If you anticipate many results, you can end a stream early to prevent
144+
* // unnecessary processing and API requests.
145+
* //-
146+
* search.getIndexes()
147+
* .on('data', function(index) {
148+
* this.end();
149+
* });
141150
*/
142151
Search.prototype.getIndexes = function(query, callback) {
143152
var self = this;

lib/storage/bucket.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,15 @@ Bucket.prototype.file = function(name, options) {
396396
* .on('end', function() {
397397
* // All files retrieved.
398398
* });
399+
*
400+
* //-
401+
* // If you anticipate many results, you can end a stream early to prevent
402+
* // unnecessary processing and API requests.
403+
* //-
404+
* bucket.getFiles()
405+
* .on('data', function(file) {
406+
* this.end();
407+
* });
399408
*/
400409
Bucket.prototype.getFiles = function(query, callback) {
401410
var self = this;

lib/storage/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,15 @@ Storage.prototype.createBucket = function(name, metadata, callback) {
290290
* .on('end', function() {
291291
* // All buckets retrieved.
292292
* });
293+
*
294+
* //-
295+
* // If you anticipate many results, you can end a stream early to prevent
296+
* // unnecessary processing and API requests.
297+
* //-
298+
* gcs.getBuckets()
299+
* .on('data', function(bucket) {
300+
* this.end();
301+
* });
293302
*/
294303
Storage.prototype.getBuckets = function(query, callback) {
295304
var that = this;

0 commit comments

Comments
 (0)