@@ -97,29 +97,23 @@ module.exports = class FeedReader extends EventEmitter {
9797 */
9898 read ( callback ) {
9999 let ended = false ;
100- let aborted = false ;
101100 let req ;
102101 let items = [ ] ;
103102 let newItems = [ ] ;
104103 let sortOrder = 0 ;
105104
106- const error = ( abort , err ) => {
105+ const error = ( err ) => {
107106 ended = true ;
108107 this . first = false ;
109- if ( ! aborted ) {
110- if ( typeof callback === 'function' ) {
111- callback ( err ) ;
112- } else {
113- this . emit ( 'error' , err ) ;
114- }
115- }
116- if ( abort && ! aborted ) {
117- aborted = true ;
118- req . abort ( ) ;
108+ if ( typeof callback === 'function' ) {
109+ callback ( err ) ;
110+ } else {
111+ this . emit ( 'error' , err ) ;
119112 }
113+ req . destroy ( ) ;
120114 } ;
121115
122- const success = ( abort ) => {
116+ const success = ( ) => {
123117 if ( ended ) { return ; }
124118 ended = true ;
125119 if ( sortOrder <= 0 ) {
@@ -131,9 +125,8 @@ module.exports = class FeedReader extends EventEmitter {
131125 }
132126 newItems . forEach ( this . emit . bind ( this , 'item' ) ) ;
133127 this . emit ( 'items' , newItems ) ;
134- if ( abort && ! aborted ) {
135- aborted = true ;
136- req . abort ( ) ;
128+ if ( req ) {
129+ req . destroy ( ) ;
137130 }
138131 if ( typeof callback === 'function' ) {
139132 callback ( null , newItems ) ;
@@ -184,7 +177,7 @@ module.exports = class FeedReader extends EventEmitter {
184177
185178 // Create feed parser.
186179 const parser = new FeedMe ( ) ;
187- parser . on ( 'error' , error . bind ( null , true ) ) ;
180+ parser . on ( 'error' , error ) ;
188181
189182 // Try to get date from one of the fields.
190183 parser . once ( 'pubdate' , getdate ) ;
@@ -272,7 +265,7 @@ module.exports = class FeedReader extends EventEmitter {
272265 // Check if this item has already been read in previous requests
273266 // if it has, then stop parsing the rest of the document.
274267 parser . removeListener ( 'item' , getItem ) ;
275- success ( true ) ;
268+ success ( ) ;
276269 }
277270 }
278271 } ;
@@ -304,6 +297,6 @@ module.exports = class FeedReader extends EventEmitter {
304297 req . on ( 'end' , onEnd ) ;
305298 } ) ;
306299
307- req . on ( 'error' , error . bind ( null , false ) ) ;
300+ req . on ( 'error' , error ) ;
308301 }
309302} ;
0 commit comments