Skip to content

Conversation

@bsneed
Copy link
Contributor

@bsneed bsneed commented Oct 15, 2022

  • Added OutputFileStream class to shield us a little from Swift's back-and-forth/deprecations on FileHandle.
  • Added storage stress tests to test suite.
  • Improved some existing test cases.
  • Added errorHandler to configuration so developer can receive errors we see internally.

Affects #154 and #162.

@bsneed bsneed force-pushed the bsneed/storage_fixes branch from f5f2eb3 to 9e85e20 Compare October 15, 2022 23:03
@bsneed bsneed force-pushed the bsneed/storage_fixes branch from fd25215 to 81cc70b Compare October 16, 2022 00:11
@bsneed bsneed changed the title Storage hardening; Expose monitoring capabilities. Storage hardening; Add error handling capabilities. Oct 21, 2022
Copy link

@oscb oscb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few questions and small comments, but overall I think this looks good!

}

@discardableResult
func errorHandler(_ value: @escaping (Error) -> Void) -> Configuration {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious as to why it returns the Configuration ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config methods are all chainable and this continues that. Makes is so you can do ...

let analytics = Configuration(writeKey: "1234")
                         .trackLifecycleEvents(true)
                         .apiHost("eu1.segmentapi.com")
                         .whateverElse()

.. instead of having to create an instance and then set them all afterwards.

}

/// Reports an internal error to the user-defined error handler.
public func reportInternalError(_ error: Error, hardStop: Bool = false) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe critical instead of hardStop sounds more exception-like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

named it fatal instead as it seemed more descriptive of what was going to happen, ie: YOUR APP WILL DIE.

// flushInterval and flushAt can be modified post initialization
analytics.store.subscribe(self, initialState: true) { [weak self] (state: System) in
guard let self = self else { return }
self.flushTimer = QueueTimer(interval: state.configuration.values.flushInterval) { [weak self] in
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this works in Swift but wouldn't it also have to cancel the previous timer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QueueTimer is a wrapper on a dispatch source timer. Cancel is handled in dealloc.

@bsneed bsneed merged commit b1ed208 into main Oct 25, 2022
@bsneed bsneed deleted the bsneed/storage_fixes branch October 25, 2022 17:29
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

Successfully merging this pull request may close these issues.

5 participants