Skip to content
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 Scopes #102

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Introducing Scopes #102

wants to merge 18 commits into from

Conversation

aidanm3341
Copy link
Member

@aidanm3341 aidanm3341 commented Sep 3, 2024

I have added the concept of Scopes to the MessageBroker. This is a mechanism for building a tree of message brokers in which messages will propagate up the tree until either the root is reacher, or a broker is found which has a subscriber to handle the message.

One outstanding question on this implementation is if the semantics for disposing of a scope is complete. Currently you can .destroy() a broker, which will unlink it from its parent meaning messages will no longer propagate up. Should this functionality do anything else? E.g. should it unlink itself from any children scopes as well?

@Davidhanson90
Copy link

I think we need some additional docs for this change which details about how messages propagate up and down scopes.

@Davidhanson90
Copy link

What are we doing about scope disposal. I think it needs to be part of this process.

@aidanm3341
Copy link
Member Author

aidanm3341 commented Sep 9, 2024

What are we doing about scope disposal. I think it needs to be part of this process.

That's a good point, there should be a mechanism for disposing of a scope similar to what exists for channels. This also made me realise another point - given that messages on a channel trickle down to the same channel in child scopes, the existing disposal logic should dispose of the same channel in the children.

Roaders
Roaders previously approved these changes Oct 31, 2024
main/core/messagebroker.ts Outdated Show resolved Hide resolved
Copy link

@Davidhanson90 Davidhanson90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor suggestions. Where do we stand on destroy or scopes?

main/contracts/contracts.ts Outdated Show resolved Hide resolved
main/contracts/contracts.ts Outdated Show resolved Hide resolved
main/core/messagebroker.ts Outdated Show resolved Hide resolved
@aidanm3341
Copy link
Member Author

aidanm3341 commented Nov 13, 2024

Some minor suggestions. Where do we stand on destroy or scopes?

Yes sorry I had forgotten about the scope destroying my bad. My interpretation of this would be to have the ability to disconnect the child of an instance that you have, e.g.

const broker1 = messagebroker<Contract>();
const broker2 = broker1.createScope('my-scope');
broker1.destroyScope('my-scope');

broker2.get('channel').subscribe(_ => console.log('hello!'));
broker1.create('channel').publish('test'); // nothing happens

so it's essentially orphaning the child broker, stopping any message propagation down to it. What do you think, is this the kind of thing you had in mind or am I misunderstanding?

@aidanm3341 aidanm3341 changed the title Preliminary Scopes Implementation Introducing Scopes Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants