@6qat/tcp-connection 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tcp-stream.js +8 -8
- package/package.json +1 -1
package/dist/tcp-stream.js
CHANGED
|
@@ -4,12 +4,12 @@ export const createTcpConnection = (options) => {
|
|
|
4
4
|
// Create queues for incoming and outgoing data
|
|
5
5
|
const incomingQueue = yield* Queue.unbounded();
|
|
6
6
|
const outgoingQueue = yield* Queue.unbounded();
|
|
7
|
-
// Use refs for coordinated cleanup
|
|
8
|
-
const isClosing = yield* Ref.make(false);
|
|
9
7
|
// Track error count
|
|
10
8
|
const writeErrorCount = yield* Ref.make(0);
|
|
9
|
+
// Use refs for coordinated cleanup
|
|
10
|
+
const isClosing = yield* Ref.make(false);
|
|
11
11
|
// Safely shut down once
|
|
12
|
-
const performShutdown =
|
|
12
|
+
const performShutdown = Effect.gen(function* () {
|
|
13
13
|
const alreadyClosing = yield* Ref.getAndSet(isClosing, true);
|
|
14
14
|
if (alreadyClosing)
|
|
15
15
|
return;
|
|
@@ -22,7 +22,7 @@ export const createTcpConnection = (options) => {
|
|
|
22
22
|
Queue.shutdown(incomingQueue),
|
|
23
23
|
Queue.shutdown(outgoingQueue),
|
|
24
24
|
]);
|
|
25
|
-
})
|
|
25
|
+
});
|
|
26
26
|
// Create deferred for connection cleanup
|
|
27
27
|
const bunSocket = yield* Effect.tryPromise(() => Bun.connect({
|
|
28
28
|
port: options.port,
|
|
@@ -31,12 +31,12 @@ export const createTcpConnection = (options) => {
|
|
|
31
31
|
data(_socket, data) {
|
|
32
32
|
Queue.unsafeOffer(incomingQueue, data);
|
|
33
33
|
},
|
|
34
|
-
error(_socket,
|
|
34
|
+
error(_socket, _error) {
|
|
35
35
|
//Queue.unsafeOffer(incomingQueue, error)
|
|
36
|
-
Effect.
|
|
36
|
+
Effect.runPromise(performShutdown);
|
|
37
37
|
},
|
|
38
38
|
close(_socket) {
|
|
39
|
-
Effect.
|
|
39
|
+
Effect.runPromise(performShutdown);
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
})).pipe(Effect.timeout(options.timeout ?? Duration.millis(3000)), Effect.flatMap((maybeSocket) => maybeSocket
|
|
@@ -65,7 +65,7 @@ export const createTcpConnection = (options) => {
|
|
|
65
65
|
return Effect.sleep(Duration.millis(100)).pipe(Effect.flatMap(() => Queue.offer(outgoingQueue, data)));
|
|
66
66
|
},
|
|
67
67
|
}))),
|
|
68
|
-
}), Effect.
|
|
68
|
+
}), Effect.fork);
|
|
69
69
|
// Cleanup procedure
|
|
70
70
|
const close = Effect.gen(function* () {
|
|
71
71
|
console.log("Closing connection");
|