Fork me on GitHub
#core-async
<
2016-05-05
>
angusiguess01:05:48

Shaping? How so?

pre02:05:33

A Dispatcher is a mini router.

pre02:05:56

Any communication between an external queue to a channel, and vice versa, typically goes through the same set of validations, rules, policies that is otherwise required in a scenario where a router is required.

pre02:05:02

I don’t have a right answer yet, but I believe that discussing the shape of the message can help better supervisors.

pre02:05:24

“Shaping the channels” is essentially using a higher-level abstraction to bind multiple async/pipelines.

d-t-w05:05:42

Hey @mss, I use (s/protocol impl/Channel) to identify channels w/ Schema, but I go one step further.

d-t-w05:05:30

within my core.async utils I have a

d-t-w05:05:32

(def Channel (s/protocol impl/Channel))

(s/defn chan :- (s/protocol s/Schema)
  "Channel schema, val defines the schema of of successful takes (does not include Throwable, which is implicit)"
  [val :- s/Any]
  Channel)

d-t-w05:05:40

then I can either:

d-t-w05:05:55

(s/defn write-batch :- es.async/Channel e.g. write-batch will return a channel

d-t-w05:05:05

(s/defn read-catalog :- (es.async/chan Event) e.g. read-catalog will return a channel of Event

d-t-w05:05:54

both resolve to the same thing (the fn is basically a no-op), but one gives me more information about the schema of vals I expect to be returned on the channel (it has no impact on validation, it's purely for documentation)

d-t-w05:05:28

the comment about Throwable relates to the standard model of exception handling that I apply to channel processing.

danielcompton09:05:00

@d-t-w: could you do validation with a transducer?

d-t-w09:05:22

I'm not sure it would be a good idea to enforce schema on the elements of a channel, and with my exception handling it's always possible that the value may be an ex-info. You could have a transducer that validates each element, but you would need to apply that xform to the channel at channel creation time, and that may be outside the scope of the fn you're adding the schema validation to.

d-t-w09:05:37

just the documentation tends to be enough for me

angusiguess14:05:07

@pri: Sounds a little bit like a pipeline feeding a pubsub?

angusiguess14:05:51

@d-t-w: I tend to agree that in production validating channel contents is probably not a great idea, but I'm into the idea of having a transducer that validates in dev.

angusiguess14:05:08

However, if you turn on all validation in dev you kind of get that for free when the functions that consume from channels choke.

angusiguess14:05:17

Or the producing functions break schema.

angusiguess14:05:02

All of your transforming functions could be schemafied, the only trick is figuring out how to handle exceptions that come out of schema validation.

angusiguess14:05:00

My general feeling so far is that we should test functions, not channels. Channels should dictate very little about behaviour.

angusiguess14:05:24

And pipelines can be tested piecemeal by testing each of the transforming functions (or the composed ones)

pre17:05:25

@d-t-w: we pass on a tuple of [events-chan, finalize-chan, error-chan] at the start and cascade them from our schemafied functions. A global error channel can admix them and monitor for error flows and metrics. You’re spot on with testing functions, not channels. Channels should dictate operations.

pre17:05:13

Oops, I think that was for @angusiguess.

angusiguess17:05:24

that's pretty interesting!