-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing channels #3308
Introducing channels #3308
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the Channel
abstraction over both receiving messages and sending them. 👌
```ts | ||
const rpcSubscriptions = | ||
// Step 1 - Create an `RpcSubscriptions` instance. This may be stateful. | ||
createSolanaRpcSubscriptions(mainnet('wss://api.mainnet-beta.solana.com')); | ||
const response = await rpcSubscriptions | ||
// Step 2 - Call supported methods on it to produce `PendingRpcSubscriptionsRequest` objects. | ||
.slotNotifications({ commitment: 'confirmed' }) | ||
// Step 3 - Call the `subscribe()` method on those pending requests to trigger them. | ||
.subscribe({ abortSignal: AbortSignal.timeout(10_000) }); | ||
// Step 4 - Iterate over the result. | ||
try { | ||
for await (const slotNotification of slotNotifications) { | ||
console.log('Got a slot notification', slotNotification); | ||
} | ||
} catch (e) { | ||
console.error('The subscription closed unexpectedly', e); | ||
} finally { | ||
console.log('We have stopped listening for notifications'); | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this example is more suited for rpc-subscriptions
than rpc-subscriptions-spec
since it's the highest-level API we offer.
Perhaps it would be better to offer examples on how to use the new type here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I literally just copy-pasted this from @solana/rpc-spec
.
I honestly don't understand the differences anymore.
Help me, Obi Wan…
ad092cf
to
e4260af
Compare
7e8d6ca
to
f44dc4a
Compare
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/[email protected] |
Merge activity
|
f44dc4a
to
997f4ca
Compare
Summary
Subscriptions are different from one-shot requests in that they need two things: a ‘transport’ to fulfil requests to subscribe to some kind of notifications, but also a ‘channel’ over which to send that subscription and wait for notifications. Channels might be shared by many subscriptions, so they need to be treated as a separate type.
In this PR we create the concept of the
RpcSubscriptionsChannel
and theRpcSubscriptionsChannelCreator
.