(body: Effect.Effect<A, OpenApiInvocationError, never>)
| 1245 | }), |
| 1246 | ); |
| 1247 | const readResponseBody = <A>(body: Effect.Effect<A, OpenApiInvocationError, never>) => |
| 1248 | Effect.gen(function* () { |
| 1249 | const bodyExitOption = yield* Effect.callback< |
| 1250 | Option.Option<Exit.Exit<A, OpenApiInvocationError>> |
| 1251 | >((resume, signal) => { |
| 1252 | let settled = false; |
| 1253 | const bodyEffect = body.pipe( |
| 1254 | Effect.exit, |
| 1255 | Effect.tap((exit) => |
| 1256 | Effect.sync(() => { |
| 1257 | if (settled) return; |
| 1258 | settled = true; |
| 1259 | clearTimeout(timer); |
| 1260 | resume(Effect.succeed(Option.some(exit))); |
| 1261 | }), |
| 1262 | ), |
| 1263 | ); |
| 1264 | const fiber = runFork(bodyEffect); |
| 1265 | const interrupt = () => { |
| 1266 | runFork(Fiber.interrupt(fiber)); |
| 1267 | }; |
| 1268 | const timer = setTimeout(() => { |
| 1269 | if (settled) return; |
| 1270 | settled = true; |
| 1271 | interrupt(); |
| 1272 | resume(Effect.succeed(Option.none())); |
| 1273 | }, responseBodyTimeoutMs); |
| 1274 | signal.addEventListener("abort", interrupt, { once: true }); |
| 1275 | return Effect.sync(() => { |
| 1276 | clearTimeout(timer); |
| 1277 | signal.removeEventListener("abort", interrupt); |
| 1278 | if (!settled) interrupt(); |
| 1279 | }); |
| 1280 | }); |
| 1281 | if (Option.isNone(bodyExitOption)) { |
| 1282 | return yield* new OpenApiInvocationError({ |
| 1283 | message: responseBodyTimeoutMessage(responseBodyTimeoutMs), |
| 1284 | statusCode: Option.some(status), |
| 1285 | reason: "response_body_timeout", |
| 1286 | }); |
| 1287 | } |
| 1288 | const bodyExit = bodyExitOption.value; |
| 1289 | if (Exit.isFailure(bodyExit)) return yield* Effect.failCause(bodyExit.cause); |
| 1290 | return bodyExit.value; |
| 1291 | }); |
| 1292 | const responseBodyBinding = Option.getOrUndefined(operation.responseBody); |
| 1293 | const fileHint = responseBodyBinding |
| 1294 | ? Option.getOrUndefined(responseBodyBinding.fileHint) |
no test coverage detected