@jsenv/server
Advanced tools
Comparing version 12.3.2 to 12.3.3
{ | ||
"name": "@jsenv/server", | ||
"version": "12.3.2", | ||
"version": "12.3.3", | ||
"description": "Write your Node.js server using pure functions", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
// https://github.com/jamestalmage/stream-to-observable/blob/master/index.js | ||
import { Readable } from "node:stream" | ||
import { createObservable } from "./observable.js" | ||
@@ -10,2 +9,8 @@ | ||
const observable = createObservable(({ next, error, complete }) => { | ||
if (nodeStream.isPaused()) { | ||
nodeStream.resume() | ||
} else if (nodeStream.complete) { | ||
complete() | ||
return null | ||
} | ||
const cleanup = () => { | ||
@@ -18,9 +23,13 @@ nodeStream.removeListener("data", next) | ||
} | ||
// should we do nodeStream.resume() in case the stream was paused ? | ||
nodeStream.once("error", error) | ||
nodeStream.on("data", next) | ||
nodeStream.once("close", cleanup) | ||
nodeStream.once("end", complete) | ||
nodeStream.on("data", (data) => { | ||
next(data) | ||
}) | ||
nodeStream.once("close", () => { | ||
cleanup() | ||
}) | ||
nodeStream.once("end", () => { | ||
complete() | ||
}) | ||
return cleanup | ||
@@ -27,0 +36,0 @@ }) |
@@ -233,2 +233,6 @@ import http from "node:http" | ||
const requestCallback = async (nodeRequest, nodeResponse) => { | ||
// pause the stream to let a chance to "requestToResponse" | ||
// to call "requestRequestBody". Without this the request body readable stream | ||
// might be closed when we'll try to attach "data" and "end" listeners to it | ||
nodeRequest.pause() | ||
if (!nagle) { | ||
@@ -313,3 +317,2 @@ nodeRequest.connection.setNoDelay(true) | ||
} | ||
nodeRequest.on("error", (error) => { | ||
@@ -688,2 +691,3 @@ if (error.message === "aborted") { | ||
}) | ||
nodeRequest.resume() | ||
if (receiveRequestOperation.signal.aborted) { | ||
@@ -690,0 +694,0 @@ return |
134716
4198