Skip to content

Commit 51d0a28

Browse files
committed
Merge branch 'feature/update-deps' into develop
2 parents c161a19 + 336d6fe commit 51d0a28

16 files changed

+10397
-66
lines changed

.babelrc

-20
This file was deleted.

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# project
22
/.nyc_output/
33
/build/
4-
/coverage/
54
/scratch/
65

76
# node

.idea/jsLibraryMappings.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/build.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/cover.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/flow.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/full_test.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/lint.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/test.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
language: node_js
22
node_js:
33
- 'node'
4+
- '8'
45
- '6'
5-
- '4.5'
6-
- '4'
76
install: make -j4 build
87
script: make full-test

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ test: build
6666

6767
cover: node_modules
6868
cd lib && BABEL_ENV=cover nyc ${test_command}
69-
mv lib/coverage .
7069

7170
clean:
7271
rm -rf build .nyc_output

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33

44
## Overview
55

6-
`stream-to-async-iterator` provides a wrapper that implements `Symbol.asyncIterator`. This will allow streams to be usable
7-
as async iterables that can be used in for-await-of loops.
6+
`stream-to-async-iterator` provides a wrapper that implements `Symbol.asyncIterator`. This will allow streams to be
7+
usable as async iterables that can be used in for-await-of loops.
88

9-
Supports node.js 4 and up.
9+
Supports node.js 6 and up.
1010

1111
## Installation
1212

1313
```
1414
$ npm install stream-to-async-iterator
1515
```
1616

17-
The examples provides use async/await syntax for for-of loops. This assumes you are in an environment that natively
17+
The included examples use async/await syntax for for-of loops. This assumes you are in an environment that natively
1818
supports this new syntax, or that you use a tool such as Babel. In addition, for async iterators to work properly,
1919
the `Symbol.asyncIterator` symbol must be defined. Core-js or `babel-polyfill` can both help with that.
2020

lib/stream-to-async-iterator.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ type Reject = (err: any) => void;
4848
* the options for each iteration.
4949
*/
5050
export default class StreamToAsyncIterator<TVal> {
51+
_stream: Readable;
52+
_error: ?Error;
53+
_state: Symbol;
54+
_size: ?number;
55+
_rejections: Set<Reject>;
56+
5157
/**
5258
* @param {Readable} stream
5359
* @param {StreamToAsyncIterator~Options} [options]
@@ -65,7 +71,7 @@ export default class StreamToAsyncIterator<TVal> {
6571
* @private
6672
* @type {?Error}
6773
*/
68-
this._error = null;
74+
this._error = undefined;
6975

7076
/**
7177
* The current state of the iterator (not readable, readable, ended, errored)
@@ -103,13 +109,7 @@ export default class StreamToAsyncIterator<TVal> {
103109
stream.once('end', handleStreamEnd);
104110
}
105111

106-
_stream: Readable;
107-
_error: ?Error;
108-
_state: Symbol;
109-
_size: ?number;
110-
_rejections: Set<Reject>;
111-
112-
//todo: flow is now working with this method in place
112+
//todo: flow is not working with this method in place
113113
// [Symbol.asyncIterator]() {
114114
// return this;
115115
// }
@@ -125,16 +125,16 @@ export default class StreamToAsyncIterator<TVal> {
125125

126126
//need to wait until the stream is readable or ended
127127
try {
128-
await Promise.race([read.promise, end.promise]);
129-
return this.next();
128+
await Promise.race([read.promise, end.promise]);
129+
return this.next();
130130
}
131131
catch (e) {
132-
throw e
132+
throw e;
133133
}
134134
finally {
135-
//need to clean up any hanging event listeners
136-
read.cleanup()
137-
end.cleanup()
135+
//need to clean up any hanging event listeners
136+
read.cleanup();
137+
end.cleanup();
138138
}
139139
} else if (this._state === states.ended) {
140140
return {done: true};
@@ -164,15 +164,15 @@ export default class StreamToAsyncIterator<TVal> {
164164
//let is used here instead of const because the exact reference is
165165
//required to remove it, this is why it is not a curried function that
166166
//accepts resolve & reject as parameters.
167-
let eventListener = null;
167+
let eventListener = undefined;
168168

169169
const promise = new Promise((resolve, reject) => {
170170
eventListener = () => {
171171
this._state = states.readable;
172172
this._rejections.delete(reject);
173173

174-
// we set this to null to info the clean up not to do anything
175-
eventListener = null;
174+
// we set this to undefined to info the clean up not to do anything
175+
eventListener = undefined;
176176
resolve();
177177
};
178178

@@ -187,7 +187,7 @@ export default class StreamToAsyncIterator<TVal> {
187187
this._stream.removeListener('readable', eventListener);
188188
};
189189

190-
return { cleanup, promise }
190+
return { cleanup, promise };
191191
}
192192

193193
/**
@@ -196,14 +196,14 @@ export default class StreamToAsyncIterator<TVal> {
196196
* @returns {Promise}
197197
*/
198198
_untilEnd(): PromiseWithCleanUp<void> {
199-
let eventListener = null;
199+
let eventListener = undefined;
200200

201201
const promise = new Promise((resolve, reject) => {
202202
eventListener = () => {
203203
this._state = states.ended;
204204
this._rejections.delete(reject);
205205

206-
eventListener = null
206+
eventListener = undefined;
207207
resolve();
208208
};
209209

@@ -216,7 +216,7 @@ export default class StreamToAsyncIterator<TVal> {
216216
this._stream.removeListener('end', eventListener);
217217
};
218218

219-
return { cleanup, promise }
219+
return { cleanup, promise };
220220
}
221221
}
222222

lib/test/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
22
import 'source-map-support/register';
3-
import 'babel-polyfill';
43

54

65
Error.stackTraceLimit = Infinity;

0 commit comments

Comments
 (0)