Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't call quit in a async function. #9313

Closed
kayabaNerve opened this issue Oct 11, 2018 · 5 comments
Closed

Can't call quit in a async function. #9313

kayabaNerve opened this issue Oct 11, 2018 · 5 comments
Labels
Async Everything related to Nim's async

Comments

@kayabaNerve
Copy link
Collaborator

Minimized code sample:

import asyncdispatch

proc a() {.async.} =
    echo "Hi"
    quit(0)

The compiler fails with:

test.nim(3, 10) template/generic instantiation from here
test.nim(4, 5) Error: unreachable statement after 'return'
@LemonBoy
Copy link
Contributor

Yeah, the async macro doesn't know about quit being noreturn and inserts a complete(retFuture...) after it.

@LemonBoy LemonBoy added the Async Everything related to Nim's async label Oct 11, 2018
@qqtop
Copy link

qqtop commented Aug 20, 2019

Currently I put the quit(0) into a proc. This seems to work

import asyncdispatch

proc a(mybool:bool) : Future[string] {.async.} =
   
   proc qt() = echo "Bye-Bye";quit(0)
   
   if mybool == true:
      qt()
   else:
      echo "Hello" 

while true:
    for _ in 0 ..< 3:  
        asyncCheck a(false)
    asyncCheck a(true)
runforever()

@ghost
Copy link

ghost commented Jun 25, 2020

Works on devel:

import asyncdispatch

proc a() {.async.} =
  echo "Hi"
  quit(0)

waitFor a()

Add a test-case probably?

@timotheecour
Copy link
Member

Probably got fixed by my recent defer bugfix, yes, test case needed

@timotheecour
Copy link
Member

closed by #14795

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Async Everything related to Nim's async
Projects
None yet
Development

No branches or pull requests

4 participants