Skip to content

Commit 5bbd796

Browse files
Use setImmediate if available
1 parent 3cb5838 commit 5bbd796

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

sink.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ var ready = require('./ready');
88
<<< examples/write.js
99
1010
**/
11+
12+
var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick
13+
1114
module.exports = function(socket, opts) {
1215
return function (read) {
1316
opts = opts || {}
@@ -22,7 +25,6 @@ module.exports = function(socket, opts) {
2225
socket.addEventListener('close', function (ev) {
2326
if(ev.wasClean || ev.code === 1006) onClose()
2427
else {
25-
console.log(ev)
2628
var err = new Error('ws error')
2729
err.event = ev
2830
onClose(err)
@@ -40,9 +42,8 @@ module.exports = function(socket, opts) {
4042
if (end) {
4143
return read(end, function () {});
4244
}
43-
4445
socket.send(data);
45-
process.nextTick(function() {
46+
nextTick(function() {
4647
read(null, next);
4748
});
4849
});
@@ -51,6 +52,3 @@ module.exports = function(socket, opts) {
5152
read(null, next);
5253
}
5354
}
54-
55-
56-

0 commit comments

Comments
 (0)