FAQ
I'm working on an application that could iteratively fetch a large number
of items from the web.

The existing Python version returns a list and a boolean, indicating that
there is more to fetch.

I'm thinking about returning a 'chan<- *Item' and pushing the items as they
come in. The problem is error handling. I would hate to panic over some
http error. Would it be really dumb to return a chan <- error as well and
push an error if one occurs?

That is the function would look like FetchItems(collectionName string)
(chan<- Item, chan<- error)

Search Discussions

  • Dave Cheney at Sep 2, 2012 at 10:38 pm
    Here are two approaches I have used in the past

    1. package the result into a struct, http://play.golang.org/p/enY27tMV_B

    2. use a chan interface{} and switch on the result,
    http://play.golang.org/p/broVgTkD-l

    Cheers

    Dave

    On Mon, Sep 3, 2012 at 8:19 AM, Doug Fort wrote:
    I'm working on an application that could iteratively fetch a large number of
    items from the web.

    The existing Python version returns a list and a boolean, indicating that
    there is more to fetch.

    I'm thinking about returning a 'chan<- *Item' and pushing the items as they
    come in. The problem is error handling. I would hate to panic over some http
    error. Would it be really dumb to return a chan <- error as well and push an
    error if one occurs?

    That is the function would look like FetchItems(collectionName string)
    (chan<- Item, chan<- error)
  • Doug Fort at Sep 3, 2012 at 12:40 am

    On Sun, Sep 2, 2012 at 6:38 PM, Dave Cheney wrote:
    Here are two approaches I have used in the past

    1. package the result into a struct, http://play.golang.org/p/enY27tMV_B

    2. use a chan interface{} and switch on the result,
    http://play.golang.org/p/broVgTkD-l
    Thanks. I think either approach is preferable to the two channels. I'm
    leaning toward the interface channel.
    Cheers

    Dave

    On Mon, Sep 3, 2012 at 8:19 AM, Doug Fort wrote:
    I'm working on an application that could iteratively fetch a large number of
    items from the web.

    The existing Python version returns a list and a boolean, indicating that
    there is more to fetch.

    I'm thinking about returning a 'chan<- *Item' and pushing the items as they
    come in. The problem is error handling. I would hate to panic over some http
    error. Would it be really dumb to return a chan <- error as well and push an
    error if one occurs?

    That is the function would look like FetchItems(collectionName string)
    (chan<- Item, chan<- error)


    --
    Doug Fort, Consulting Programmer
    http://www.dougfort.com
  • Daniel Huckstep at Sep 3, 2012 at 1:53 am
    I don't think the two channel approach is that bad. Then you just use the
    select statement and don't have to worry about type problems (as with the
    single channel with an interface{}).
    On Sep 2, 2012 6:40 PM, "Doug Fort" wrote:
    On Sun, Sep 2, 2012 at 6:38 PM, Dave Cheney wrote:
    Here are two approaches I have used in the past

    1. package the result into a struct, http://play.golang.org/p/enY27tMV_B

    2. use a chan interface{} and switch on the result,
    http://play.golang.org/p/broVgTkD-l
    Thanks. I think either approach is preferable to the two channels. I'm
    leaning toward the interface channel.
    Cheers

    Dave

    On Mon, Sep 3, 2012 at 8:19 AM, Doug Fort wrote:
    I'm working on an application that could iteratively fetch a large
    number of
    items from the web.

    The existing Python version returns a list and a boolean, indicating
    that
    there is more to fetch.

    I'm thinking about returning a 'chan<- *Item' and pushing the items as
    they
    come in. The problem is error handling. I would hate to panic over some
    http
    error. Would it be really dumb to return a chan <- error as well and
    push an
    error if one occurs?

    That is the function would look like FetchItems(collectionName string)
    (chan<- Item, chan<- error)


    --
    Doug Fort, Consulting Programmer
    http://www.dougfort.com
  • Jesse McNelis at Sep 3, 2012 at 2:19 am

    On Mon, Sep 3, 2012 at 11:53 AM, Daniel Huckstep wrote:
    I don't think the two channel approach is that bad. Then you just use the
    select statement and don't have to worry about type problems (as with the
    single channel with an interface{}).
    The problem with selecting between a data and error channel is that if
    you get an error on the
    error channel you need to drain the data channel before handling the
    error. Which looks a little weird.



    --
    =====================
    http://jessta.id.au

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 2, '12 at 10:26p
activeSep 3, '12 at 2:19a
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase