the-moby-effect
Version:
Moby/Docker API client built using effect-ts
28 lines • 1.31 kB
JavaScript
import * as Function from "effect/Function";
import * as Sink from "effect/Sink";
import * as Tuple from "effect/Tuple";
import { demuxMultiplexedToSingleSink, isMultiplexedChannel, isMultiplexedSocket } from "./multiplexed.js";
import { demuxRawToSingleSink, isRawChannel, isRawSocket } from "./raw.js";
/**
* Demux either a raw socket or a multiplexed socket to a single sink.
*
* @since 1.0.0
* @category Demux
*/
export const demuxToSingleSink = /*#__PURE__*/Function.dual(
/**
* We are data-first if the first argument is a channel or if the first
* argument is an object with a "stdout", "stderr", or "stdin" key.
*/
arguments_ => isRawSocket(arguments_[0]) || isRawChannel(arguments_[0]) || isMultiplexedSocket(arguments_[0]) || isMultiplexedChannel(arguments_[0]),
// Implementation, need the type parameters for checking the underlying.
(socketOptions, source, sink, options) => {
if (isRawSocket(socketOptions) || isRawChannel(socketOptions)) {
return demuxRawToSingleSink(socketOptions, source, sink, options);
}
if (isMultiplexedSocket(socketOptions) || isMultiplexedChannel(socketOptions)) {
return demuxMultiplexedToSingleSink(socketOptions, source, Sink.mapInput(sink, Tuple.get(1)), options);
}
return Function.absurd(socketOptions);
});
//# sourceMappingURL=demux.js.map