refactor with async/await

Trying to be more robust about error handling and failure.
This commit is contained in:
Roman Shtylman
2016-07-09 17:06:13 -07:00
parent f12f1c81b3
commit a2a58f4c6f
10 changed files with 290 additions and 221 deletions

View File

@@ -1,6 +1,6 @@
var http = require('http');
var util = require('util');
var assert = require('assert');
import http from 'http';
import util from 'util';
import assert from 'assert';
// binding agent will return a given options.socket as the socket for the agent
// this is useful if you already have a socket established and want the request
@@ -20,4 +20,4 @@ function create_connection(port, host, options) {
return this.socket;
}
module.exports = BindingAgent;
export default BindingAgent;

View File

@@ -1,11 +1,11 @@
// all url safe
// can't use uppercase because hostnames are lowercased
var chars = 'abcdefghijklmnopqrstuvwxyz';
const chars = 'abcdefghijklmnopqrstuvwxyz';
module.exports = function rand_id() {
var randomstring = '';
export default function rand_id() {
let randomstring = '';
for (var i=0; i<10; ++i) {
var rnum = Math.floor(Math.random() * chars.length);
const rnum = Math.floor(Math.random() * chars.length);
randomstring += chars[rnum];
}