using io.MultiWriter

446 views
Skip to first unread message

Vasiliy Tolstov

unread,
Jun 6, 2012, 5:17:06 AM6/6/12
to golang-nuts
Hello. I'm try to use io.MultiWriter via writing to local cache file
and http.WriteCloser, but in source file of multiwriter function each
writer not run in parallel, why?
For example if the http client has poor network speed writing to local
file may be delayed. If the local fs is slowdown - writing to client
may be delayed...

Who not spawn for each writer new goroutine?

--
Vasiliy Tolstov,
Clodo.ru
e-mail: v.to...@selfip.ru
jabber: va...@selfip.ru

Andrew Gerrand

unread,
Jun 6, 2012, 5:51:25 AM6/6/12
to Vasiliy Tolstov, golang-nuts
On 6 June 2012 19:17, Vasiliy Tolstov <v.to...@selfip.ru> wrote:
> Hello. I'm try to use io.MultiWriter via writing to local cache file
> and http.WriteCloser, but in source file of multiwriter function each
> writer not run in parallel, why?
> For example if the http client has poor network speed writing to local
> file may be delayed. If the local fs is slowdown - writing to client
> may be delayed...
>
> Who not spawn for each writer new goroutine?

io.MultiWriter is a simple primitive whose behavior easy to understand.

An implementation like the one you describe would need to buffer data
for the slower writer, and wouldn't be able to return a write error if
a buffered write failed. There are a lot of questions about how such a
thing should be designed, and their answers depend a lot on how they
are used.

Fortunately, Go's concurrency features make it pretty easy to write
the multiwriter that you need, depending on your particular use.

Andrew
Reply all
Reply to author
Forward
0 new messages