Skip to content

Commit

Permalink
chore: configure eslint to enforce promise rules
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Dec 11, 2022
1 parent 6dfeb86 commit b7d01a9
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 226 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"rules": {
"space-before-function-paren": 0,
"import/export": 0
"import/export": 0,
"promise/catch-or-return": "error"
}
}
16 changes: 10 additions & 6 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Http3Server extends Http3WebTransport {
/** @type {Record<string, ReadableStream>} */
this.sessionStreams = {}

/** @type {Record<string, ReadableStreamController<Http3WTSession>>} */
/** @type {Record<string, ReadableStreamDefaultController<Http3WTSession>>} */
this.sessionController = {}

this.port = null
Expand Down Expand Up @@ -101,7 +101,9 @@ export class Http3Server extends Http3WebTransport {
this.sessionController[path] = controller
}
})
if (!args || !args.noAutoPaths) this.transportInt.addPath(path)
if (!args || !args.noAutoPaths) {
this.transportInt.addPath(path)
}
return this.sessionStreams[path]
}

Expand All @@ -111,17 +113,19 @@ export class Http3Server extends Http3WebTransport {
onSessionRequest(args) {
if (args.promise && args.header) {
if (!this.requestHandler) throw new Error('Request handler not set')
this.requestHandler({ header: args.header }).then(
(/** @type {any} */ result) => {
this.requestHandler({ header: args.header })
.then((/** @type {any} */ result) => {
log('oSR', result)
this.transportInt.finishSessionRequest({
promise: args.promise,
header: args.header,
session: args.session,
...result
})
}
)
})
.catch((/** @type {any} */ err) => {
log.error(err)
})
} else throw new Error('onSessionRequest')
}

Expand Down
12 changes: 8 additions & 4 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ export class Http3WTStream {
this.pendingoperation = new Promise((resolve, reject) => {
this.pendingres = resolve
})
const dataprom = this.parentobj.waitForDatagramsSend()
dataprom.finally(() => {
this.objint.writeChunk(chunk)
})
this.parentobj
.waitForDatagramsSend()
.finally(() => {
this.objint.writeChunk(chunk)
})
.catch((/** @type {any} */ err) => {
log.error(err)
})
return this.pendingoperation
} else {
log.trace('chunk info:', chunk)
Expand Down
1 change: 1 addition & 0 deletions lib/webtransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class WebTransport {

this.datagrams = sessionint.datagrams

/** @type {ReadableStream<WebTransportBidirectionalStream>} */
this.incomingBidirectionalStreams = sessionint.incomingBidirectionalStreams

this.incomingUnidirectionalStreams =
Expand Down
82 changes: 42 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/datagrams.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('datagrams', function () {
let closed = false

// write datagrams until the server receives one and closes the connection
// eslint-disable-next-line promise/catch-or-return
Promise.resolve().then(async () => {
// eslint-disable-next-line no-unmodified-loop-condition
while (!closed) {
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/read-stream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @template T
* @typedef {import('node:stream/web').ReadableStream<T>} ReadableStream<T>
*/

/**
* Read a stream contents to the end and return it
*
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/reader-value.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @template T
* @typedef {import('node:stream/web').ReadableStream<T>} ReadableStream<T>
*/

/**
* @template T
* @param {ReadableStream<T>} readableStream
Expand Down
Loading

0 comments on commit b7d01a9

Please sign in to comment.