-
Notifications
You must be signed in to change notification settings - Fork 653
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
feat: NIO.TimeAmount(string:) and TimeAmount.description #3046
base: main
Are you sure you want to change the base?
Conversation
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.
Code walkthrough comments to kick things off.
Sources/NIOCore/EventLoop.swift
Outdated
extension TimeAmount: CustomStringConvertible { | ||
|
||
/// Errors thrown when parsint a TimeAmount from a string | ||
public enum ValidationError: Error, Equatable { |
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 sure it's a great idea to introduce a new public error type. Can I get away with re-using something?
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 doubt that anybody would really catch that error, so we could also just make this an internal
error type. That way you can still throw & print it but NIO wouldn't be forced into the API.
Alright, cleaned this up. Thank you for taking a look at this quickly, and agreeing to have this as part of NIO, @Lukasa! |
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.
Nice one, thanks!
Sources/NIOCore/EventLoop.swift
Outdated
/// - defaultUnit: Unit to use if no unit is specified in the string | ||
/// | ||
/// - Throws: ValidationError if the string cannot be parsed | ||
public init(_ userProvidedString: String, defaultUnit: String = "s") throws { |
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.
FWIW, I wouldn't default defaultUnit
to anything. Why is it seconds?
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.
Yeah, this honestly makes sense AND this is not covered in tests, one sec.
Head branch was pushed to by a user without write access
Adds
TimeAmount.init(string:)
andTimeAmount.description
for parsing time amounts from strings and pretty printing them.Closes #2504.
Motivation:
Had a minute, wanted to work on Swift-NIO a bit more, and saw @weissi still wanted this.
Modifications:
It's largely based on the snippet @weissi made in #2504 with a few changes:
.gitignore
to ignore.build
everywhere, I've got a few of them when testing locally.Open questions:
1h 31m
, but decided against it. Feels like an edge case. Happy to add this if you think it's needed.