Skip to content

Commit 2fdde81

Browse files
committed
Update examples and prevent further reading of a stream if the stream has been destroyed
1 parent 677a3eb commit 2fdde81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+222
-220
lines changed

lib/node_modules/@stdlib/random/streams/arcsine/README.md

+9-12
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,21 @@ var randomStream = require( '@stdlib/random/streams/arcsine' );
3737
Returns a [readable stream][readable-stream] for generating pseudorandom numbers drawn from an [arcsine][arcsine] distribution with parameters `a` (minimum support) and `b` (maximum support).
3838

3939
```javascript
40-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
40+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
4141

4242
var iStream;
4343
var stream;
44-
var count;
4544

46-
function log( chunk ) {
47-
count += 1;
45+
function log( chunk, idx ) {
4846
console.log( chunk.toString() );
49-
if ( count === 10 ) {
47+
if ( idx === 10 ) {
5048
stream.destroy();
5149
}
5250
}
5351

5452
stream = randomStream( 2.0, 5.0 );
5553
iStream = inspectStream( log );
5654

57-
count = 0;
5855
stream.pipe( iStream );
5956
```
6057

@@ -86,7 +83,7 @@ var stream = randomStream( 2.0, 5.0, opts );
8683
By default, the function returns a [stream][stream] which can generate an infinite number of values (i.e., the [stream][stream] will **never** end). To limit the number of generated pseudorandom numbers, set the `iter` option.
8784

8885
```javascript
89-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
86+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
9087

9188
function log( chunk ) {
9289
console.log( chunk.toString() );
@@ -105,7 +102,7 @@ stream.pipe( iStream );
105102
By default, when not operating in [objectMode][object-mode], a returned [stream][stream] delineates generated pseudorandom numbers using a newline character. To specify an alternative separator, set the `sep` option.
106103

107104
```javascript
108-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
105+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
109106

110107
function log( chunk ) {
111108
console.log( chunk.toString() );
@@ -125,7 +122,7 @@ stream.pipe( iStream );
125122
To seed the underlying pseudorandom number generator, set the `seed` option.
126123

127124
```javascript
128-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
125+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
129126

130127
function log( v ) {
131128
console.log( v );
@@ -150,7 +147,7 @@ stream.pipe( iStream );
150147
To return a [readable stream][readable-stream] with an underlying pseudorandom number generator having a specific initial state, set the `state` option.
151148

152149
```javascript
153-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
150+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
154151

155152
function log( v ) {
156153
console.log( v );
@@ -361,7 +358,7 @@ The method accepts the same `options` as [`randomStream()`](#random-stream).
361358
This method is a convenience function to create [streams][stream] which **always** operate in [objectMode][object-mode].
362359

363360
```javascript
364-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
361+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
365362

366363
function log( v ) {
367364
console.log( v );
@@ -433,7 +430,7 @@ function onState( state ) {
433430
<!-- eslint no-undef: "error" -->
434431

435432
```javascript
436-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
433+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
437434
var randomStream = require( '@stdlib/random/streams/arcsine' );
438435

439436
function log( v ) {

lib/node_modules/@stdlib/random/streams/arcsine/docs/repl.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
> function fcn( chunk ) { console.log( chunk.toString() ); };
9393
> var opts = { 'iter': 10 };
9494
> var s = {{alias}}( 2.0, 5.0, opts );
95-
> var o = {{alias:@stdlib/streams/utils/inspect}}( fcn );
95+
> var o = {{alias:@stdlib/streams/utils/inspect-sink}}( fcn );
9696
> s.pipe( o );
9797

9898

@@ -254,7 +254,7 @@
254254
> function fcn( v ) { console.log( v ); };
255255
> var opts = { 'iter': 10 };
256256
> var s = {{alias}}.objectMode( 2.0, 5.0, opts );
257-
> var o = {{alias:@stdlib/streams/utils/inspect}}.objectMode( fcn );
257+
> var o = {{alias:@stdlib/streams/utils/inspect-sink}}.objectMode( fcn );
258258
> s.pipe( o );
259259

260260
See Also

lib/node_modules/@stdlib/random/streams/arcsine/examples/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
'use strict';
2020

21-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
21+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
2222
var randomStream = require( './../lib' );
2323

2424
function log( v ) {

lib/node_modules/@stdlib/random/streams/arcsine/lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @module @stdlib/random/streams/arcsine
2525
*
2626
* @example
27-
* var inspectStream = require( '@stdlib/streams/utils/inspect' );
27+
* var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
2828
* var randomStream = require( '@stdlib/random/streams/arcsine' );
2929
*
3030
* function log( chunk ) {
@@ -59,7 +59,7 @@
5959
* }
6060
*
6161
* @example
62-
* var inspectStream = require( '@stdlib/streams/utils/inspect' );
62+
* var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
6363
* var randomStream = require( '@stdlib/random/streams/arcsine' );
6464
*
6565
* function log( v ) {

lib/node_modules/@stdlib/random/streams/arcsine/lib/main.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ function read() {
112112
var FLG;
113113
var r;
114114

115+
if ( this._destroyed ) {
116+
return;
117+
}
115118
FLG = true;
116119
while ( FLG ) {
117120
r = this._prng.next();
@@ -209,7 +212,7 @@ function destroy( error ) {
209212
* @returns {RandomStream} Stream instance
210213
*
211214
* @example
212-
* var inspectStream = require( '@stdlib/streams/utils/inspect' );
215+
* var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
213216
*
214217
* function log( chunk ) {
215218
* console.log( chunk.toString() );

lib/node_modules/@stdlib/random/streams/arcsine/lib/object_mode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var RandomStream = require( './main.js' );
5050
* @returns {RandomStream} Stream instance
5151
*
5252
* @example
53-
* var inspectStream = require( '@stdlib/streams/utils/inspect' );
53+
* var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
5454
*
5555
* function log( v ) {
5656
* console.log( v );

lib/node_modules/@stdlib/random/streams/arcsine/test/test.main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var isUint32Array = require( '@stdlib/assert/is-uint32array' );
3030
var UINT32_MAX = require( '@stdlib/constants/math/uint32-max' );
3131
var Uint32Array = require( '@stdlib/array/uint32' );
3232
var minstd = require( '@stdlib/random/base/minstd' );
33-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
33+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
3434
var randomStream = require( './../lib/main.js' );
3535

3636

lib/node_modules/@stdlib/random/streams/arcsine/test/test.object_mode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var tape = require( 'tape' );
2424
var Uint32Array = require( '@stdlib/array/uint32' );
2525
var UINT32_MAX = require( '@stdlib/constants/math/uint32-max' );
26-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
26+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
2727
var RandomStream = require( './../lib/main.js' );
2828
var objectMode = require( './../lib/object_mode.js' );
2929

lib/node_modules/@stdlib/random/streams/box-muller/README.md

+9-12
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,21 @@ var randomStream = require( '@stdlib/random/streams/box-muller' );
3737
Returns a [readable stream][readable-stream] for generating pseudorandom numbers drawn from a [standard normal][normal] distribution using the [Box-Muller transform][@stdlib/random/base/box-muller].
3838

3939
```javascript
40-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
40+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
4141

4242
var iStream;
4343
var stream;
44-
var count;
4544

46-
function log( chunk ) {
47-
count += 1;
45+
function log( chunk, idx ) {
4846
console.log( chunk.toString() );
49-
if ( count === 10 ) {
47+
if ( idx === 10 ) {
5048
stream.destroy();
5149
}
5250
}
5351

5452
stream = randomStream();
5553
iStream = inspectStream( log );
5654

57-
count = 0;
5855
stream.pipe( iStream );
5956
```
6057

@@ -86,7 +83,7 @@ var stream = randomStream( opts );
8683
By default, the function returns a [stream][stream] which can generate an infinite number of values (i.e., the [stream][stream] will **never** end). To limit the number of generated pseudorandom numbers, set the `iter` option.
8784

8885
```javascript
89-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
86+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
9087

9188
function log( chunk ) {
9289
console.log( chunk.toString() );
@@ -105,7 +102,7 @@ stream.pipe( iStream );
105102
By default, when not operating in [objectMode][object-mode], a returned [stream][stream] delineates generated pseudorandom numbers using a newline character. To specify an alternative separator, set the `sep` option.
106103

107104
```javascript
108-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
105+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
109106

110107
function log( chunk ) {
111108
console.log( chunk.toString() );
@@ -125,7 +122,7 @@ stream.pipe( iStream );
125122
To seed the underlying pseudorandom number generator, set the `seed` option.
126123

127124
```javascript
128-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
125+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
129126

130127
function log( v ) {
131128
console.log( v );
@@ -150,7 +147,7 @@ stream.pipe( iStream );
150147
To return a [readable stream][readable-stream] with an underlying pseudorandom number generator having a specific initial state, set the `state` option.
151148

152149
```javascript
153-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
150+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
154151

155152
function log( v ) {
156153
console.log( v );
@@ -341,7 +338,7 @@ The method accepts the same `options` as [`randomStream()`](#random-stream).
341338
This method is a convenience function to create [streams][stream] which **always** operate in [objectMode][object-mode].
342339

343340
```javascript
344-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
341+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
345342

346343
function log( v ) {
347344
console.log( v );
@@ -413,7 +410,7 @@ function onState( state ) {
413410
<!-- eslint no-undef: "error" -->
414411

415412
```javascript
416-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
413+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
417414
var randomStream = require( '@stdlib/random/streams/box-muller' );
418415

419416
function log( v ) {

lib/node_modules/@stdlib/random/streams/box-muller/docs/repl.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
> function fcn( chunk ) { console.log( chunk.toString() ); };
8787
> var opts = { 'iter': 10 };
8888
> var s = {{alias}}( opts );
89-
> var o = {{alias:@stdlib/streams/utils/inspect}}( fcn );
89+
> var o = {{alias:@stdlib/streams/utils/inspect-sink}}( fcn );
9090
> s.pipe( o );
9191

9292

@@ -230,7 +230,7 @@
230230
> function fcn( v ) { console.log( v ); };
231231
> var opts = { 'iter': 10 };
232232
> var s = {{alias}}.objectMode( opts );
233-
> var o = {{alias:@stdlib/streams/utils/inspect}}.objectMode( fcn );
233+
> var o = {{alias:@stdlib/streams/utils/inspect-sink}}.objectMode( fcn );
234234
> s.pipe( o );
235235

236236
See Also

lib/node_modules/@stdlib/random/streams/box-muller/examples/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
'use strict';
2020

21-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
21+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
2222
var randomStream = require( './../lib' );
2323

2424
function log( v ) {

lib/node_modules/@stdlib/random/streams/box-muller/lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @module @stdlib/random/streams/box-muller
2525
*
2626
* @example
27-
* var inspectStream = require( '@stdlib/streams/utils/inspect' );
27+
* var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
2828
* var randomStream = require( '@stdlib/random/streams/box-muller' );
2929
*
3030
* function log( chunk ) {
@@ -59,7 +59,7 @@
5959
* }
6060
*
6161
* @example
62-
* var inspectStream = require( '@stdlib/streams/utils/inspect' );
62+
* var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
6363
* var randomStream = require( '@stdlib/random/streams/box-muller' );
6464
*
6565
* function log( v ) {

lib/node_modules/@stdlib/random/streams/box-muller/lib/main.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ function read() {
110110
var FLG;
111111
var r;
112112

113+
if ( this._destroyed ) {
114+
return;
115+
}
113116
FLG = true;
114117
while ( FLG ) {
115118
r = this._prng.next();
@@ -202,7 +205,7 @@ function destroy( error ) {
202205
* @returns {RandomStream} Stream instance
203206
*
204207
* @example
205-
* var inspectStream = require( '@stdlib/streams/utils/inspect' );
208+
* var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
206209
*
207210
* function log( chunk ) {
208211
* console.log( chunk.toString() );

lib/node_modules/@stdlib/random/streams/box-muller/lib/object_mode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var RandomStream = require( './main.js' );
4545
* @returns {RandomStream} Stream instance
4646
*
4747
* @example
48-
* var inspectStream = require( '@stdlib/streams/utils/inspect' );
48+
* var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
4949
*
5050
* function log( v ) {
5151
* console.log( v );

lib/node_modules/@stdlib/random/streams/box-muller/test/test.main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var isUint32Array = require( '@stdlib/assert/is-uint32array' );
3030
var UINT32_MAX = require( '@stdlib/constants/math/uint32-max' );
3131
var Uint32Array = require( '@stdlib/array/uint32' );
3232
var minstd = require( '@stdlib/random/base/minstd' );
33-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
33+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
3434
var randomStream = require( './../lib/main.js' );
3535

3636

lib/node_modules/@stdlib/random/streams/box-muller/test/test.object_mode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var tape = require( 'tape' );
2424
var Uint32Array = require( '@stdlib/array/uint32' );
2525
var UINT32_MAX = require( '@stdlib/constants/math/uint32-max' );
26-
var inspectStream = require( '@stdlib/streams/utils/inspect' );
26+
var inspectStream = require( '@stdlib/streams/utils/inspect-sink' );
2727
var RandomStream = require( './../lib/main.js' );
2828
var objectMode = require( './../lib/object_mode.js' );
2929

0 commit comments

Comments
 (0)