Skip to content

Commit

Permalink
Simplify promises
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-m authored Jun 10, 2019
1 parent e3d6187 commit 60610ba
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ const http = require('http')
const process = require('process')
const WebSocket = require('ws')

const manualPromise = () => {
let result
const promise = new Promise((resolve, reject) => (result = { resolve, reject }))
return { ...result, promise }
}

const serversPatched = new WeakSet()

function createWebsocketMiddleware (propertyName = 'ws', options) {
Expand Down Expand Up @@ -39,12 +33,9 @@ function createWebsocketMiddleware (propertyName = 'ws', options) {

if (~upgradeHeader.indexOf('websocket')) {
debug(`websocket middleware in use on route ${ctx.path}`)
ctx[propertyName] = async () => {
const { promise, resolve } = manualPromise()
ctx[propertyName] = new Promise((resolve) => {
wss.handleUpgrade(ctx.req, ctx.request.socket, Buffer.alloc(0), resolve)
ctx.respond = false

return promise
}
}

Expand Down

0 comments on commit 60610ba

Please sign in to comment.