Giter VIP home page Giter VIP logo

Comments (10)

daurnimator avatar daurnimator commented on July 17, 2024

I had a go at adding this feature tonight. over on a branch: https://github.com/daurnimator/cqueues/commits/thread-on-error
Please review :)

from cqueues.

wahern avatar wahern commented on July 17, 2024

On Sun, Jan 11, 2015 at 08:34:26PM -0800, daurnimator wrote:

I had a go at adding this feature tonight. over on a branch: https://github.com/daurnimator/cqueues/commits/thread-on-error
Please review :)

One of the TODO items I had in mind was to tweak cqueues:wrap and
cqueues:attach to return a unique identifier which could then be used to
communicate information about a context just like this.

The actual thread object is an obvious choice, but what if we want to
eventually recycle threads? If we provide context for errors, it would make
sense to also provide a way to communicate which threads finished normally.
If we use the thread object as the identifier returned from cqueues:attach
and :wrap, then we can't reycle the threads--maybe somebody put it in a weak
table so it could detect when it's GC'd.

But maybe that's not a particularly useful feature. It also conflicts with
the return signature and usage pattern of :step, and perhaps other
inconsistencies.

Your patch still works, but if something like the above was implement we
might need to return 4 values.

from cqueues.

daurnimator avatar daurnimator commented on July 17, 2024

The actual thread object is an obvious choice, but what if we want to
eventually recycle threads?

Well that doesn't work with :attach anyway.

Reusing threads with :wrap is interesting though.

If we provide context for errors, it would make
sense to also provide a way to communicate which threads finished normally.
If we use the thread object as the identifier returned from cqueues:attach
and :wrap, then we can't reycle the threads--maybe somebody put it in a weak
table so it could detect when it's GC'd.

Does it?

You cannot recycle a thread that has had an error, it is "dead" (as returned by coroutine.status).
I limited the patch to this case (only errors), as there was nothing else you can use the thread object for again.

The actual 'thread' object is required, as I will want to be able to use it with the debug.* apis that take a thread as a first parameter.

But maybe that's not a particularly useful feature. It also conflicts with
the return signature and usage pattern of :step, and perhaps other
inconsistencies.

Your patch still works, but if something like the above was implement we
might need to return 4 values.

I think returning the thread in the :step() failure case is absolutely fine.
What to return in the success/running case can be left as an open question.

from cqueues.

daurnimator avatar daurnimator commented on July 17, 2024

Any more thoughts here?

from cqueues.

wahern avatar wahern commented on July 17, 2024

I'm sold. Only question mark is what the return signature should be for :step. Should it be

local ok, errmsg, errno, thr = loop:step()

or

local ok, errmsg, errno_or_thr = loop:step()

or something else? Some errors might not be related to a specific thread. Or a thread error might have an associated errno.

from cqueues.

daurnimator avatar daurnimator commented on July 17, 2024

Hmm, I didn't think about errno. at least in the handler I modified in my branch I didn't see it...

Or a thread error might have an associated errno.

How would that occur?

from cqueues.

daurnimator avatar daurnimator commented on July 17, 2024

Infact, are there any circumstances where :step returns an errno?

from cqueues.

wahern avatar wahern commented on July 17, 2024

Right now, no. But that's because we either throw on error, or discard the errno after formatting the error message. Even if we return the thread, some of those thread errors involve a system error that we would want to return directly so the user doesn't have to parse the message.

I'm thinking maybe the return signature should look like:

local ok, msg, errno, thr = loop:step()

or even

local ok, msg, errno, thr, obj = loop:step()

were obj is the object that triggered the error.

The most common error will likely be en error thrown by the thread itself, in which case errno will be nil and it might seem dumb to have a hole in the list like that. But it seems the best out of all the alternatives. Thoughts?

from cqueues.

daurnimator avatar daurnimator commented on July 17, 2024

Right now, no.

So lets add it if we think it's reasonable. Should be lua_pushinteger(L, error) at line 1671: https://github.com/wahern/cqueues/blob/master/src/cqueues.c#L1671 and then an extra thing to xmove

I'm thinking maybe the return signature should look like:

local ok, msg, errno, thr = loop:step()
or even

local ok, msg, errno, thr, obj = loop:step()
were obj is the object that triggered the error.

Lets go with the former for now. we can add the poll object later if it seems to be required.

from cqueues.

wahern avatar wahern commented on July 17, 2024

Fixed with 0c43868, followed by bug fix in 8f6645f.

from cqueues.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.