@@ -2,16 +2,6 @@ import http from 'http'
2
2
import { host , port , serverUrl , iters } from '../config'
3
3
import PerformanceTimer from '../PerformanceTimer'
4
4
5
- const reqOptions = {
6
- hostname : host ,
7
- port : port ,
8
- path : '/hello' ,
9
- method : 'POST' ,
10
- headers : { 'Content-Type' : 'application/json' }
11
- }
12
-
13
- const postData = JSON . stringify ( { name : 'Fran' } )
14
-
15
5
// Would be great to have Promise.defer :_(
16
6
class Deferred {
17
7
resolve = null
@@ -24,7 +14,7 @@ class Deferred {
24
14
}
25
15
}
26
16
27
- async function request ( reqOptions ) {
17
+ async function request ( reqOptions , postData ) {
28
18
const deferred = new Deferred ( ) // Promise.defer() => not supported
29
19
30
20
const req = http . request ( reqOptions , resp => {
@@ -55,6 +45,16 @@ async function request(reqOptions) {
55
45
export async function runTest ( ) {
56
46
console . log ( `Http client connecting to http://${ host } :${ port } ` )
57
47
48
+ const reqOptions = {
49
+ hostname : host ,
50
+ port : port ,
51
+ path : '/hello' ,
52
+ method : 'POST' ,
53
+ headers : { 'Content-Type' : 'application/json' }
54
+ }
55
+
56
+ const postData = JSON . stringify ( { name : 'Fran' } )
57
+
58
58
const timer = new PerformanceTimer ( )
59
59
60
60
console . log ( `Running test with ${ iters } iterations...` )
@@ -63,9 +63,8 @@ export async function runTest() {
63
63
64
64
let i = iters
65
65
await ( async function asyncLoop ( ) {
66
- const data = await request ( serverUrl , reqOptions )
66
+ const data = await request ( reqOptions , postData )
67
67
const { hello } = data
68
- console . log ( hello )
69
68
70
69
if ( -- i === 0 ) return
71
70
await asyncLoop ( )
0 commit comments