Skip to content

Shutdown to gain a callback version #230

@ktoso

Description

@ktoso

Our shutdown is async yet we only expose a blocking version of wait() on the Shutdown object.

    public struct Shutdown {
        private let receptacle: BlockingReceptacle<Void>

        init(receptacle: BlockingReceptacle<Void>) {
            self.receptacle = receptacle
        }

        public func wait(atMost timeout: TimeAmount) throws {
            guard self.receptacle.wait(atMost: timeout) != nil else {
                throw TimeoutError(message: "Shutdown did not complete", timeout: timeout)
            }
        }

        public func wait() {
            self.receptacle.wait()
        }
    }

Users may want to just provide a callback to run on completion of the shutdown.

NIO's API shape is

func shutdownGracefully(queue: DispatchQueue, _ callback: @escaping (Error?) -> Void)

So something similar could be good.

We assume the global queue currently, so we perhaps should rather ask to be provided the queue to use as well.

Metadata

Metadata

Assignees

Labels

size/SSmall task. (A couple of hours of work.)

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions