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

transducers on write-ch receive formatted value #59

Open
AlexHill opened this issue Oct 24, 2019 · 5 comments
Open

transducers on write-ch receive formatted value #59

AlexHill opened this issue Oct 24, 2019 · 5 comments

Comments

@AlexHill
Copy link

I want to apply a transformation to everything I send up my websocket, so I thought I could pass a channel with a mapping transducer as write-ch.

This doesn't work as I'd hoped because my transducer sees messages after formatting, not before. So I have to thaw, apply the transformation, and freeze again in my transducer.

Ideally, I think the formatting would occur as the last thing before writing to and the first thing after reading from the websocket connection - so read-from-ws! and write-from-ws! would take a formatter, and apply thaw and freeze respectively, rather than involving core.async at all.

That way the user-supplied channels will always be dealing with unformatted values, which I suspect will be what people want/expect almost all the time, and we lose a bit of core.async overhead inside of chord. This would break backwards compatibility in that the change could break anyone passing a channel with a transducer as write-ch. However I suspect most uses of read-ch and write-ch are to apply buffering as all mine were until today :)

Happy to make this pull request if you like the idea!

@jarohen
Copy link
Owner

jarohen commented Oct 24, 2019

Hey Alex, thanks for getting in touch :)

Yep, I agree - would certainly be useful to be able to apply a transducer before formatting, although I'd like to try avoid a breaking change if possible - you can bet that it will break someone's workflow!

Thinking out loud:

  • I wonder whether we could introduce an additional pre-freeze/post-thaw channel?
  • Maybe we could allow the user to supply transducers?
  • Is it Chord's responsibility at all? what would a user have to do if Chord didn't support it? (maybe the answer to this will influence what the Chord API change should be?)

What do you think?

Cheers,

James

@AlexHill
Copy link
Author

AlexHill commented Oct 25, 2019 via email

@jarohen
Copy link
Owner

jarohen commented Oct 28, 2019

Cheers - all good suggestions.

On balance I prefer the new :read-chan/:write-chan option - it gives the user the option to create the channel however they'd like (they may even have one in hand already) and also insulates us against future changes to how people might be able to create core.async channels. Would it be something you'd have time to create a PR for?

James

@AlexHill
Copy link
Author

Yep, I can make a PR.

So to summarise: I’ll add :read-chan and :write-chan options. These will be mutually exclusive with :read-ch and :write-ch - chord will throw if they’re used together.

The existing behaviour will be preserved when the existing options are used.

I’ll update the docs deprecating the existing options and describing the behaviour of the new ones.

@jarohen
Copy link
Owner

jarohen commented Oct 29, 2019

Great, cheers 😄

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

No branches or pull requests

2 participants