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

Experiment: Allow Core to be wrapped in a middleware #317

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

charypar
Copy link
Member

@charypar charypar commented Feb 9, 2025

This is a bit work in progress, but it's a start of a potential approach to allowing "hybrid" shells - part written in Rust, part written in Kotlin/Swift/TypeScript...

The main change is an introduction of a crux_core::Middleware trait, which is implemented by the Core and expected by the Bridge to be implemented by the provided core type. This allows middlewares to be inserted between the Bridge and the Core. Because the middleware may stack up, I've also switched the Core to return an iterator over effects, to avoid unnecessary allocations in case the middleware chain ends up long.

As part of the experiment I've implemented a Key-Value capability using a HashMap for the storage, which catches the KV effects and resolves them against the store. It turns out it's pretty involved, because resolving he effects may produce follow up effects which need to also be potentially processed and so on, creating a mutually recursive loop.

Doing that with existing iterators turned out quite difficult, so I've resorted to an odd specialised queueing FlatMap sort of thing, which seems like it might be a beginning of some more helpful abstraction.

I'll keep this open for now so that folks can experiment and see how it works out for them and we can iterate on it before we land on something solid.

Note that this would be a breaking change, so I'd like us to get it right, rather than releasing five breaking iterations 😓

@charypar charypar requested a review from StuartHarris February 9, 2025 22:36
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.

1 participant