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

? operator doesn't work with {.async.} pragma #47

Closed
tbekas opened this issue Aug 31, 2023 · 2 comments
Closed

? operator doesn't work with {.async.} pragma #47

tbekas opened this issue Aug 31, 2023 · 2 comments

Comments

@tbekas
Copy link
Contributor

tbekas commented Aug 31, 2023

It would be nice to make this syntax work:

proc computeValue(): Type {.async.} =
  let
    a = ? await service.getSomeValueAsync()
    b = ? await service.getAnotherValueAsync()
    c = ? someComputation(a, b)
  return c

## where proc signatures are
proc getSomeValueAsync(self: Service): Future[?!SomeType]

proc getAnotherValueAsync(self: Service): Future[?!AnotherType]

proc someComputation(a: SomeType, b: AnotherType): ?!Outcome

Currently we have to use without which is more verbose

proc computeValue(): Type  {.async.} =

  without a =? await service.getSomeValueAsync(), err:
    return failure(err)

  without b =? await service.getAnotherValueAsync(), err:
    return failure(err)

  without c =? someComputation(a, b), err:
    return failure(err)

  return c
@markspanbroek
Copy link
Member

That would be very nice indeed. The early return ? operator on results is from https://github.com/arnetheduck/nim-results.

There have been some discussions about this problem before:
status-im/nim-stew#37
status-im/nim-chronos#217

No solution yet, as far as I can tell.

@tbekas
Copy link
Contributor Author

tbekas commented Aug 31, 2023

Thanks for the info, I'll close this issue then since it's a duplicate and the ? operator is from a different project.

@tbekas tbekas closed this as completed Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants