Git Product home page Git Product logo

Comments (4)

arnetheduck avatar arnetheduck commented on September 26, 2024

you can:

proc process() {.async.} =
  raise (ref ValueError)()

proc ignoreExceptions(fut: Future[void]): Future[void] {.async.} =
  try:
    await fut
  except CatchableError as exc:
    debugEcho "fail"

asyncSpawn ignoreExceptions process()

asyncSpawn/asyncCheck exist to deliberately check for uncaught exceptions - just like raising in a thread without catching would terminate the program. discard process(...) will also make chronos ignore exceptions though it's poor style.

from nim-chronos.

arnetheduck avatar arnetheduck commented on September 26, 2024

if the user uses asyncSpawn, that's nothing you can control - there's no way to prevent that from raising a Defect - this is by design, the program would be in an inconsistent state at that point (because it would try to raise an exception through the processing loop which leads to resource leaks et al. This is a contributing reason why asyncdispatch has so many leaks and problems for example.

from nim-chronos.

PhilippMDoerner avatar PhilippMDoerner commented on September 26, 2024

Check, so this sentence of mine is incorrect:

I would like to be able to catch ValueError (or an exception containing it) outside of asyncProc, as "normal" errors such as this do not represent a sufficiently erroneous case to crash the thread to me.

Exceptions thrown by running the dispatcher instead of by some awaited future are a sufficiently erroneous case as you pointed out, due to potential resource leaks etc.

If I want to protect the user therefore my best choice is likely to mandate them not raise an exception, e.g via using raises: []

from nim-chronos.

arnetheduck avatar arnetheduck commented on September 26, 2024

mandate them not raise an exception,

indeed - it is likely asyncSpawn will start showing a compile-time warning whenever someone uses it without raises: []. asyncCheck is deprecated already for similar reasons.

from nim-chronos.

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.