switch to done.reject for error handling

This commit is contained in:
Philipp Kunz 2016-09-25 19:41:12 +02:00
parent 224b39f0a6
commit 084a47096d
3 changed files with 7 additions and 27 deletions

5
dist/index.d.ts vendored
View File

@ -15,17 +15,12 @@ export interface ICustomEventObject {
*/ */
export declare class Smartstream { export declare class Smartstream {
private streamArray; private streamArray;
private errorFunction;
private customEventObjectArray; private customEventObjectArray;
private streamStartedDeferred; private streamStartedDeferred;
/** /**
* constructor * constructor
*/ */
constructor(streamArrayArg: any[]); constructor(streamArrayArg: any[]);
/**
* attach an error handler to the stream to prevent throwing
*/
onError(errorFunctionArg: IErrorFunction): void;
/** /**
* make something with the stream itself * make something with the stream itself
*/ */

15
dist/index.js vendored
View File

@ -9,17 +9,10 @@ class Smartstream {
*/ */
constructor(streamArrayArg) { constructor(streamArrayArg) {
this.streamArray = []; this.streamArray = [];
this.errorFunction = null;
this.customEventObjectArray = []; this.customEventObjectArray = [];
this.streamStartedDeferred = plugins.q.defer(); this.streamStartedDeferred = plugins.q.defer();
this.streamArray = streamArrayArg; this.streamArray = streamArrayArg;
} }
/**
* attach an error handler to the stream to prevent throwing
*/
onError(errorFunctionArg) {
this.errorFunction = errorFunctionArg;
}
/** /**
* make something with the stream itself * make something with the stream itself
*/ */
@ -53,9 +46,9 @@ class Smartstream {
if (firstIteration === true) { if (firstIteration === true) {
finalStream = stream; finalStream = stream;
} }
if (this.errorFunction !== null) { stream.on('error', (err) => {
stream.on('error', this.errorFunction); done.reject(err);
} });
for (let customEventObject of this.customEventObjectArray) { for (let customEventObject of this.customEventObjectArray) {
stream.on(customEventObject.eventName, customEventObject.eventFunction); stream.on(customEventObject.eventName, customEventObject.eventFunction);
} }
@ -78,4 +71,4 @@ class Smartstream {
} }
} }
exports.Smartstream = Smartstream; exports.Smartstream = Smartstream;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90c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zRSxDQUFDO1lBQ0QsRUFBRSxDQUFDLENBQUMsQ0FBQyxjQUFjLENBQUMsQ0FBQyxDQUFDO2dCQUNsQixXQUFXLEdBQUcsV0FBVyxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsQ0FBQTtZQUMxQyxDQUFDO1lBQ0QsY0FBYyxHQUFHLEtBQUssQ0FBQTtRQUMxQixDQUFDO1FBRUQsSUFBSSxDQUFDLHFCQUFxQixDQUFDLE9BQU8sRUFBRSxDQUFBO1FBRXBDLFdBQVcsQ0FBQyxFQUFFLENBQUMsS0FBSyxFQUFDO1lBQ2pCLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNsQixDQUFDLENBQUMsQ0FBQTtRQUNGLFdBQVcsQ0FBQyxFQUFFLENBQUMsT0FBTyxFQUFDO1lBQ25CLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNsQixDQUFDLENBQUMsQ0FBQTtRQUNGLFdBQVcsQ0FBQyxFQUFFLENBQUMsUUFBUSxFQUFDO1lBQ3BCLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQTtRQUNsQixDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7Q0FDSjtBQXhFRCxrQ0F3RUMifQ==

View File

@ -18,7 +18,6 @@ export interface ICustomEventObject {
*/ */
export class Smartstream { export class Smartstream {
private streamArray = [] private streamArray = []
private errorFunction: IErrorFunction = null
private customEventObjectArray: ICustomEventObject[] = [] private customEventObjectArray: ICustomEventObject[] = []
private streamStartedDeferred = plugins.q.defer() private streamStartedDeferred = plugins.q.defer()
@ -29,13 +28,6 @@ export class Smartstream {
this.streamArray = streamArrayArg this.streamArray = streamArrayArg
} }
/**
* attach an error handler to the stream to prevent throwing
*/
onError(errorFunctionArg: IErrorFunction) {
this.errorFunction = errorFunctionArg
}
/** /**
* make something with the stream itself * make something with the stream itself
*/ */
@ -71,9 +63,9 @@ export class Smartstream {
if (firstIteration === true) { if (firstIteration === true) {
finalStream = stream finalStream = stream
} }
if (this.errorFunction !== null) { stream.on('error', (err) => {
stream.on('error', this.errorFunction) done.reject(err)
} })
for (let customEventObject of this.customEventObjectArray) { for (let customEventObject of this.customEventObjectArray) {
stream.on(customEventObject.eventName, customEventObject.eventFunction) stream.on(customEventObject.eventName, customEventObject.eventFunction)
} }