| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 939d102 commit fc9e6a3
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,32 +1,26 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - var common = require('../common'); | ||
| 3 | - var assert = require('assert'); | ||
| 4 | - var http = require('http'); | ||
| 5 | - var net = require('net'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const http = require('http'); | ||
| 5 | + const net = require('net'); | ||
| 6 | 6 | ||
| 7 | 7 | var server = http.createServer(function(req, res) { | |
| 8 | - console.log('got request. setting 1 second timeout'); | ||
| 9 | - var s = req.connection.setTimeout(500); | ||
| 10 | - assert.ok(s instanceof net.Socket); | ||
| 11 | - req.connection.on('timeout', function() { | ||
| 8 | + console.log('got request. setting 500ms timeout'); | ||
| 9 | + var socket = req.connection.setTimeout(500); | ||
| 10 | + assert.ok(socket instanceof net.Socket); | ||
| 11 | + req.connection.on('timeout', common.mustCall(function() { | ||
| 12 | 12 | req.connection.destroy(); | |
| 13 | 13 | console.error('TIMEOUT'); | |
| 14 | 14 | server.close(); | |
| 15 | - }); | ||
| 15 | + })); | ||
| 16 | 16 | }); | |
| 17 | 17 | ||
| 18 | 18 | server.listen(0, function() { | |
| 19 | 19 | console.log(`Server running at http://127.0.0.1:${this.address().port}/`); | |
| 20 | 20 | ||
| 21 | - var errorTimer = setTimeout(function() { | ||
| 22 | - throw new Error('Timeout was not successful'); | ||
| 23 | - }, common.platformTimeout(2000)); | ||
| 24 | - | ||
| 25 | - var x = http.get({port: this.address().port, path: '/'}); | ||
| 26 | - x.on('error', function() { | ||
| 27 | - clearTimeout(errorTimer); | ||
| 21 | + var request = http.get({port: this.address().port, path: '/'}); | ||
| 22 | + request.on('error', common.mustCall(function() { | ||
| 28 | 23 | console.log('HTTP REQUEST COMPLETE (this is good)'); | |
| 29 | - }); | ||
| 30 | - x.end(); | ||
| 31 | - | ||
| 24 | + })); | ||
| 25 | + request.end(); | ||
| 32 | 26 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments