swift-log-slack icon indicating copy to clipboard operation
swift-log-slack copied to clipboard

allow using a customized URLSession

Open diederich opened this issue 5 years ago • 2 comments

instead of using the shared URLSession, allow passing one in.

This allows users to pass a configued URLSession, e.g. one where they set themselves as the delegate of the session. This allows e.g. to wait for tasks to be done before exiting a console app, so slack messages can be sent.

Given we’re adding only a default parameter, this should be backwards compatible.

diederich avatar Nov 30 '20 09:11 diederich

@diederich thanks for opening this PR 🙂

I'm a little hesitant to expose the SlackSession protocol and URLSession's conformance as public API.

Maybe there's an alternative approach we could take that would still give you the hooks you're looking for?

Maybe something like closure-based handlers for when a message is queued and then sent?

wlisac avatar Dec 01 '20 04:12 wlisac

Hey @wlisac - thanks for looking into this!

The idea for making SlackSession public was that users could actually implement their own version of it if they wanted. One option would be to remove SlackSession from the public interface, and just require a URLSession.
Allowing users to pass in the URLSession, instead of using the global shared one might be worth it though.

Would that be better?

Another option, as you mentioned, might be to handle this all internally via keeping count of the messages sent etc.. It felt like that’s too much, given URLSession provides finishTasksAndInvalidate as well as invalidateAndCancel

diederich avatar Dec 02 '20 10:12 diederich