-
Notifications
You must be signed in to change notification settings - Fork 55
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
chore(async): {.async: (raises).}
for connmanager
#1172
base: master
Are you sure you want to change the base?
Conversation
{.async: (raises).}
for connmanager
{.async: (raises).}
for connmanager
@@ -67,7 +67,8 @@ type | |||
muxed: Table[PeerId, seq[Muxer]] | |||
connEvents: array[ConnEventKind, OrderedSet[ConnEventHandler]] | |||
peerEvents: array[PeerEventKind, OrderedSet[PeerEventHandler]] | |||
expectedConnectionsOverLimit*: Table[(PeerId, Direction), Future[Muxer]] | |||
expectedConnectionsOverLimit*: | |||
Table[(PeerId, Direction), Future[Muxer].Raising([CancelledError])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the difference between this and using a Future[Result[Muxer, ...]]
.
Actually, I guess the broader question would be: Is there a reason we're going for exceptions over handling errors with Result
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not an expert, but Nim natively supports exceptions and there's also compiler support for pros signatures https://nim-lang.org/docs/tut2.html#exceptions-annotating-procs-with-raised-exceptions. Result
was created in some status library. It might be painful to use Result
if Nim std wasn't designed for that. I can't say much as in general, this project uses more exceptions than Result
.
## Acquire a resource and decrement the resource | ||
## counter. If no more resources are available, | ||
## the returned future will not complete until | ||
## the resource count goes above 0. | ||
## | ||
|
||
let fut = newFuture[void]("AsyncSemaphore.acquire") | ||
let fut = Future[void].Raising([CancelledError]).init("AsyncSemaphore.acquire") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can create a new template in utils/future.nim:
template newFuture*[T](fromProc: static[string] = ""): auto =
Future[T].Raising([CancelledError]).init(fromProc)
Add
{.async: (raises).}
to connmanager.nim and to semaphore.nim (which is needed by connmanager.nim)