From 01e266eff8cb792b322e7e7a3900750b3b67e9af Mon Sep 17 00:00:00 2001 From: vince Date: Mon, 4 Nov 2024 17:48:20 +0800 Subject: [PATCH] Fix the infinite recursion issue. --- Sources/DockerClientSwift/APIs/DockerClient+Container.swift | 4 ++-- Sources/DockerClientSwift/APIs/DockerClient+Image.swift | 2 +- Sources/DockerClientSwift/APIs/DockerClient+Service.swift | 4 ++-- .../DockerClientSwift/Helper/EventLoopFuture+FlatMap.swift | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/DockerClientSwift/APIs/DockerClient+Container.swift b/Sources/DockerClientSwift/APIs/DockerClient+Container.swift index 6e7f8a2..2e8cf3c 100644 --- a/Sources/DockerClientSwift/APIs/DockerClient+Container.swift +++ b/Sources/DockerClientSwift/APIs/DockerClient+Container.swift @@ -61,7 +61,7 @@ extension DockerClient { hostConfig = CreateContainerEndpoint.CreateContainerBody.HostConfig(PortBindings: portBindingsByContainerPort) } return try client.run(CreateContainerEndpoint(imageName: image.id.value, commands: commands, exposedPorts: exposedPorts, hostConfig: hostConfig)) - .flatMap({ response in + ._flatMap({ response in try self.get(containerByNameOrId: response.Id) }) } @@ -72,7 +72,7 @@ extension DockerClient { /// - Returns: Returns an `EventLoopFuture` of active actual `PortBinding`s when the container is started. public func start(container: Container) throws -> EventLoopFuture<[PortBinding]> { return try client.run(StartContainerEndpoint(containerId: container.id.value)) - .flatMap { _ in + ._flatMap { _ in try client.run(InspectContainerEndpoint(nameOrId: container.id.value)) .flatMapThrowing { response in try response.NetworkSettings.Ports.flatMap { (containerPortSpec, bindings) in diff --git a/Sources/DockerClientSwift/APIs/DockerClient+Image.swift b/Sources/DockerClientSwift/APIs/DockerClient+Image.swift index 673f8a0..9786046 100644 --- a/Sources/DockerClientSwift/APIs/DockerClient+Image.swift +++ b/Sources/DockerClientSwift/APIs/DockerClient+Image.swift @@ -36,7 +36,7 @@ extension DockerClient { /// - Returns: Fetches the latest image information and returns an `EventLoopFuture` with the `Image` that has been fetched. public func pullImage(byIdentifier identifier: String) throws -> EventLoopFuture { return try client.run(PullImageEndpoint(imageName: identifier)) - .flatMap({ _ in + ._flatMap({ _ in try self.get(imageByNameOrId: identifier) }) } diff --git a/Sources/DockerClientSwift/APIs/DockerClient+Service.swift b/Sources/DockerClientSwift/APIs/DockerClient+Service.swift index 0331449..71e337b 100644 --- a/Sources/DockerClientSwift/APIs/DockerClient+Service.swift +++ b/Sources/DockerClientSwift/APIs/DockerClient+Service.swift @@ -31,7 +31,7 @@ extension DockerClient { /// - Returns: Returns an `EventLoopFuture` with the updated `Service`. public func update(service: Service, newImage: Image) throws -> EventLoopFuture { try client.run(UpdateServiceEndpoint(nameOrId: service.id.value, name: service.name, version: service.version, image: newImage.id.value)) - .flatMap({ _ in + ._flatMap({ _ in try self.get(serviceByNameOrId: service.id.value) }) } @@ -56,7 +56,7 @@ extension DockerClient { /// - Returns: Returns an `EventLoopFuture` with the newly created `Service`. public func create(serviceName name: String, image: Image) throws -> EventLoopFuture { try client.run(CreateServiceEndpoint(name: name, image: image.id.value)) - .flatMap({ serviceId in + ._flatMap({ serviceId in try client.run(InspectServiceEndpoint(nameOrId: serviceId.ID)) }) .map({ service in diff --git a/Sources/DockerClientSwift/Helper/EventLoopFuture+FlatMap.swift b/Sources/DockerClientSwift/Helper/EventLoopFuture+FlatMap.swift index 6f6091e..580c507 100644 --- a/Sources/DockerClientSwift/Helper/EventLoopFuture+FlatMap.swift +++ b/Sources/DockerClientSwift/Helper/EventLoopFuture+FlatMap.swift @@ -5,7 +5,7 @@ extension EventLoopFuture { /// - Parameters: /// - callback: Throwing closure that returns and `EventLoopFuture` of the result type. /// - Returns: Returns an `EventLoopFuture` with the value of the callback future. - @inlinable public func flatMap(file: StaticString = #file, line: UInt = #line, _ callback: @escaping (Value) throws -> EventLoopFuture) -> EventLoopFuture { + @inlinable func _flatMap(file: StaticString = #file, line: UInt = #line, _ callback: @escaping (Value) throws -> EventLoopFuture) -> EventLoopFuture { self.flatMap { value in do { return try callback(value) @@ -15,3 +15,4 @@ extension EventLoopFuture { } } } +