Subscription.overload
Groups several definitions of one subscription kind into a single function whose items depend on its params. A call goes to the first variant whose params accept the arguments.
import { Schema } from "effect";import { Hash } from "@ethect/core";import { Subscription, Transaction } from "@ethect/core/rpc";
const full = Schema.Literal(true);const hashes = Schema.optionalKey(Schema.Literal(false));
const pending = Subscription.overload( Subscription.make<[full: unknown]>()("newPendingTransactions", [full], Transaction.schema), Subscription.make<[full?: unknown]>()("newPendingTransactions", [hashes], Hash.schema),);
pending(); // Stream<Hash, …>: the hash of each pending transactionpending(true); // Stream<Transaction, …>: each pending transaction in fullThis is how Eth.subscribe.newPendingTransactions
is defined.
Returns
Section titled “Returns”A function with the call signatures of every variant, plus two properties:
| Property | Type | Holds |
|---|---|---|
kind |
string |
the kind of the first variant |
variants |
a tuple of Subscription |
the definitions, in order |
Parameters
Section titled “Parameters”variants
Section titled “variants”- Type: one or more
Subscription, as separate arguments
The definitions to group. They normally share a kind and differ by a literal in their params.
import { Schema } from "effect";import { Hash } from "@ethect/core";import { Block, Subscription } from "@ethect/core/rpc";
const full = Schema.Literal("full");
const heads = Subscription.overload( Subscription.make<[detail: unknown]>()("acme_heads", [full], Block.headerSchema), Subscription.make()("acme_heads", [], Hash.schema),);Behavior
Section titled “Behavior”- First match wins. The arguments are tested against each variant’s params in order: put the most specific variant first.
- No match falls back to the first variant, whose stream then fails with a
CodecErroron the params. - No
paramsoritemof its own. Read them on a variant:Eth.subscribe.newPendingTransactions.variants[0].item.