jacksonh / manos

Manos is an easy to use, easy to test, high performance web application framework that stays out of your way and makes your life ridiculously simple.
Other
455 stars 61 forks source link

Action callbacks on Write #107

Closed txdv closed 13 years ago

txdv commented 13 years ago

I wonder if it would make sense to have action callbacks on Write: Write(byte[] data, Action callback)

Is it possible, is it feasible?

In IRC you always send a command in one chunk so when one has an event which tracks the writes, it would be nice to actually fire the callback right at the moment when you actually push the data through the socket, right?

ghost commented 13 years ago

We have, you can write IEnumerables to any stream. The stream will pull data from the IEnumerables it hasn't depleted yet, and you can very much fire callbacks from within those enumerators. There is an example that does this somewhere in the source tree, see the HttpTransaction class for details.

txdv commented 13 years ago

O you mean create my own IEnumerable derived class which pretty much fires the events itself, right?

Would an overload method Write(byte[] data, Action action) hurt very much?

ghost commented 13 years ago

Yes, I mean that. The overload would be kind of useless, since calling delegates is not core functionality of streams (it's just a nice side effect of the streaming strategy we use). Build an IEnumerable<byte[]> that yields your data and calls the action instead, perhaps add an extension method to Stream?