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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Action callbacks on Write

txdv opened this issue · comments

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?

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.

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?

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?