codex-storage / questionable

Elegant optional types for Nim
Other
116 stars 5 forks source link

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

Closed tbekas closed 1 year ago

tbekas commented 1 year ago

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 commented 1 year ago

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: https://github.com/status-im/nim-stew/issues/37 https://github.com/status-im/nim-chronos/issues/217

No solution yet, as far as I can tell.

tbekas commented 1 year ago

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