Improve clarity of asyncAfter code and other timeout#259
Merged
Conversation
max-potapov
reviewed
Sep 28, 2016
| case .some(let seconds) where seconds > 0: | ||
| callbackQueue.asyncAfter(deadline: DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) { [weak self] in | ||
| let milliseconds = Int(seconds * 1_000) | ||
| callbackQueue.asyncAfter(deadline: .now() + .milliseconds(milliseconds)) { [weak self] in |
There was a problem hiding this comment.
You already have seconds to use now() + .seconds(Int(x)) function.
Contributor
Author
There was a problem hiding this comment.
That would remove the ability to specify fractional timeouts like 2.5 seconds. Well, you could pass them in, but the fractional part would be silently dropped. That's why I'm doing the conversion to milliseconds first.
Owner
|
It was and I like the clarity changes. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, I'd like to improve the clarity of the deadline calculation for Dispatch.asyncAfter in WebSocket.disconnect(). I think the existing code is a result of the Swift3 code updater and could use some syntactic sugar.
I also added underscores to time-related constants to improve legibility.