On Thu, Sep 16, 2021 at 11:17 PM yba...@gmail.com <ybau...@gmail.com> wrote:

> - Design in a non-blocking tcp way (that is let the user use
> select()/poll()/epoll() sycall).
> - Or design it with blocking tcp io inside go routines, which would return
> 2 channels (read and write). Then let the user do a channel-select in its
> main go routine.
>

Neither. Return a blocking iterator, something like

type Iterator struct {
    // Next blocks until a new message is available or the stream ends and
returns if a new message is available.
    Next() bool
    // Message returns the current message. Must only be called after Next
returns true.
    Message() []byte
    // Error returns the error reading the next message, if any.
    Error() err
}

and let the user use their own channels/goroutines, if they need it.

That is what I would consider idiomatic Go. I would not consider it
idiomatic to return/accept channels as part of your API anymore.


>
> I fail to see which one is superior to the other.
> Moreover: one is idiomatic go, but one the other hand I like the idea to
> provide a thin wrapper and let the developper user of the library to choose
> which way he handles his problematic.
>
> What would you do?
>
> Regards
> Yves
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/e900640f-edaa-4f6a-9d8e-7c751841e498n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/e900640f-edaa-4f6a-9d8e-7c751841e498n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfEO%2BFCoCYwX39i%3D2dRQE%2BXMm3b1mjcwpZ5QY%3Dc%3DkwWA4g%40mail.gmail.com.

Reply via email to