| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fa0457e commit 1860eae
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,36 +2,28 @@ | |||
| 2 | 2 | // This example sets a timeout then immediately attempts to disable the timeout | |
| 3 | 3 | // https://github.com/joyent/node/pull/2245 | |
| 4 | 4 | ||
| 5 | - var common = require('../common'); | ||
| 6 | - var net = require('net'); | ||
| 7 | - var assert = require('assert'); | ||
| 5 | + const common = require('../common'); | ||
| 6 | + const net = require('net'); | ||
| 7 | + const assert = require('assert'); | ||
| 8 | 8 | ||
| 9 | - var T = 100; | ||
| 9 | + const T = 100; | ||
| 10 | 10 | ||
| 11 | - var server = net.createServer(function(c) { | ||
| 11 | + const server = net.createServer(function(c) { | ||
| 12 | 12 | c.write('hello'); | |
| 13 | 13 | }); | |
| 14 | 14 | server.listen(common.PORT); | |
| 15 | 15 | ||
| 16 | - var killers = [0]; | ||
| 16 | + const socket = net.createConnection(common.PORT, 'localhost'); | ||
| 17 | 17 | ||
| 18 | - var left = killers.length; | ||
| 19 | - killers.forEach(function(killer) { | ||
| 20 | - var socket = net.createConnection(common.PORT, 'localhost'); | ||
| 18 | + const s = socket.setTimeout(T, function() { | ||
| 19 | + common.fail('Socket timeout event is not expected to fire'); | ||
| 20 | + }); | ||
| 21 | + assert.ok(s instanceof net.Socket); | ||
| 21 | 22 | ||
| 22 | - var s = socket.setTimeout(T, function() { | ||
| 23 | - socket.destroy(); | ||
| 24 | - if (--left === 0) server.close(); | ||
| 25 | - assert.ok(killer !== 0); | ||
| 26 | - clearTimeout(timeout); | ||
| 27 | - }); | ||
| 28 | - assert.ok(s instanceof net.Socket); | ||
| 23 | + socket.setTimeout(0); | ||
| 29 | 24 | ||
| 30 | - socket.setTimeout(killer); | ||
| 25 | + setTimeout(function() { | ||
| 26 | + socket.destroy(); | ||
| 27 | + server.close(); | ||
| 28 | + }, T * 2); | ||
| 31 | 29 | ||
| 32 | - var timeout = setTimeout(function() { | ||
| 33 | - socket.destroy(); | ||
| 34 | - if (--left === 0) server.close(); | ||
| 35 | - assert.ok(killer === 0); | ||
| 36 | - }, T * 2); | ||
| 37 | - }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments