Skip to content

Commit

Permalink
preview2-shims: Updating http RequestOptions to handle nano/milli (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
landonxjames authored Mar 6, 2024
1 parent 32cc612 commit a23cc46
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions packages/preview2-shim/lib/nodejs/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,38 @@ const responseOutparamCreate = ResponseOutparam._create;
delete ResponseOutparam._create;

class RequestOptions {
#connectTimeoutMs;
#firstByteTimeoutMs;
#betweenBytesTimeoutMs;
#connectTimeout;
#firstByteTimeout;
#betweenBytesTimeout;
//The WASI Duration is nanoseconds, js timers are set with Ms.
//We store the data as nanos, but provide TimeoutMs methods for
//convenience in setting timers elsewhere
connectTimeout() {
return this.#connectTimeout;
}
connectTimeoutMs() {
return this.#connectTimeoutMs;
return this.#connectTimeout / 1_000_000;
}
setConnectTimeout(duration) {
this.#connectTimeout = duration;
}
setConnectTimeoutMs(duration) {
this.#connectTimeoutMs = duration;
firstByteTimeout() {
return this.#firstByteTimeout;
}
firstByteTimeoutMs() {
return this.#firstByteTimeoutMs;
return this.#firstByteTimeout / 1_000_000;
}
setFirstByteTimeout(duration) {
this.#firstByteTimeout = duration;
}
setFirstByteTimeoutMs(duration) {
this.#firstByteTimeoutMs = duration;
betweenBytesTimeout() {
return this.#betweenBytesTimeout;
}
betweenBytesTimeoutMs() {
return this.#betweenBytesTimeoutMs;
return this.#betweenBytesTimeout / 1_000_000;
}
setBetweenBytesTimeoutMs(duration) {
this.#betweenBytesTimeoutMs = duration;
setBetweenBytesTimeout(duration) {
this.#betweenBytesTimeout = duration;
}
}

Expand Down

0 comments on commit a23cc46

Please sign in to comment.