stream-url
Advanced tools
Comparing version 0.0.8 to 0.0.10
{ | ||
"name": "stream-url", | ||
"version": "0.0.8", | ||
"version": "0.0.10", | ||
"homepage": "http://github.com/gritzko/stream-url", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -42,4 +42,10 @@ Stream URLs | ||
This package defines just one fictive URL protocol named `0` which | ||
masquerades local invocations for a stream. The 0 protocol is mostly | ||
useful for connecting componenets locally. It is not that useful for | ||
unit testing as it skips serialization/ deserialization for the sake | ||
of efficiency. See [test/][test] for usage examples. | ||
[go]: https://gobyexample.com/channels | ||
[stream]: https://iojs.org/api/stream.html | ||
[test]: test/01_connect_listen.js |
@@ -26,2 +26,6 @@ "use strict"; | ||
ZeroServer.prototype.listen = function (url, options, callback){ | ||
if (options && options.constructor===Function) { | ||
callback = options; | ||
options = undefined; | ||
} | ||
if (this.id) { | ||
@@ -38,3 +42,5 @@ throw new Error('can listen one id only'); | ||
ZeroServer.servers[this.id] = this; | ||
callback(null, this); | ||
if (callback) { | ||
callback(null, this); | ||
} | ||
}; | ||
@@ -41,0 +47,0 @@ |
@@ -19,3 +19,2 @@ "use strict"; | ||
module.exports = ZeroStream; | ||
// TODO OpStream hook: data is an Op !!!!!!!!!!!!!!! | ||
@@ -26,4 +25,11 @@ ZeroStream.prototype.on = function (event, callback) { | ||
this.on_data = callback; | ||
while (this.data.length) { // fake buffering | ||
callback(this.data.shift()); | ||
try { | ||
while (this.data.length) { // fake buffering | ||
callback(this.data.shift()); | ||
} | ||
} catch (ex) { | ||
console.error(ex); | ||
if (this.pair.on_error) { | ||
this.pair.on_error(ex.message); | ||
} | ||
} | ||
@@ -33,3 +39,3 @@ break; | ||
case "end": this.on_end = callback; break; | ||
case "error": /* never happens */ break; | ||
case "error": this.on_error = callback; break; | ||
default: | ||
@@ -43,3 +49,10 @@ throw new Error('unsupported event'); | ||
if (this.pair.on_data) { | ||
this.pair.on_data(something); | ||
try { | ||
this.pair.on_data(something); | ||
} catch (ex) { | ||
console.error(ex); | ||
if (this.on_error) { | ||
this.on_error(ex.message); | ||
} | ||
} | ||
} else { | ||
@@ -46,0 +59,0 @@ if (this.pair.data.length>100) { |
@@ -49,1 +49,22 @@ "use strict"; | ||
}); | ||
tape ('1.C receiver fails', function (t) { | ||
su.listen('0:failed', function(err, serv) { | ||
serv.on('connection', function(conn) { | ||
t.pass('incoming connection'); | ||
conn.on('data', function (obj) { | ||
t.equal(obj, 'test'); | ||
throw new Error('fail'); | ||
}); | ||
}); | ||
}); | ||
su.connect('0://failed', function (err, stream) { | ||
stream.on('error', function (msg) { | ||
t.pass('got error'); | ||
t.equal(msg, 'fail'); | ||
t.end(); | ||
}); | ||
stream.write('test'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12530
278
51
0