@@ -85,8 +85,8 @@ struct ConnectionStateMachine {
8585 // Connection Actions
8686
8787 // --- general actions
88- case sendParseDescribeBindExecuteSync( PostgresQuery )
89- case sendBindExecuteSync( PSQLExecuteStatement )
88+ case sendParseDescribeBindExecuteSync( PostgresQuery , promise : EventLoopPromise < Void > ? )
89+ case sendBindExecuteSync( PSQLExecuteStatement , promise : EventLoopPromise < Void > ? )
9090 case failQuery( EventLoopPromise < PSQLRowStream > , with: PSQLError , cleanupContext: CleanUpContext ? )
9191 case succeedQuery( EventLoopPromise < PSQLRowStream > , with: QueryResult )
9292
@@ -97,12 +97,12 @@ struct ConnectionStateMachine {
9797 case forwardStreamError( PSQLError , read: Bool , cleanupContext: CleanUpContext ? )
9898
9999 // Prepare statement actions
100- case sendParseDescribeSync( name: String , query: String , bindingDataTypes: [ PostgresDataType ] )
100+ case sendParseDescribeSync( name: String , query: String , bindingDataTypes: [ PostgresDataType ] , promise : EventLoopPromise < Void > ? )
101101 case succeedPreparedStatementCreation( EventLoopPromise < RowDescription ? > , with: RowDescription ? )
102102 case failPreparedStatementCreation( EventLoopPromise < RowDescription ? > , with: PSQLError , cleanupContext: CleanUpContext ? )
103103
104104 // Close actions
105- case sendCloseSync( CloseTarget )
105+ case sendCloseSync( CloseTarget , promise : EventLoopPromise < Void > ? )
106106 case succeedClose( CloseCommandContext )
107107 case failClose( CloseCommandContext , with: PSQLError , cleanupContext: CleanUpContext ? )
108108 }
@@ -234,7 +234,7 @@ struct ConnectionStateMachine {
234234 }
235235 self . state = . sslNegotiated
236236 return . establishSSLConnection
237-
237+
238238 case . initialized,
239239 . sslNegotiated,
240240 . sslHandlerAdded,
@@ -247,7 +247,7 @@ struct ConnectionStateMachine {
247247 . closing,
248248 . closed:
249249 return self . closeConnectionAndCleanup ( . unexpectedBackendMessage( . sslSupported) )
250-
250+
251251 case . modifying:
252252 preconditionFailure ( " Invalid state: \( self . state) " )
253253 }
@@ -583,14 +583,16 @@ struct ConnectionStateMachine {
583583 }
584584
585585 switch task {
586- case . extendedQuery( let queryContext) :
586+ case . extendedQuery( let queryContext, let writePromise) :
587+ writePromise? . fail ( psqlErrror) /// Use `cleanupContext` or not?
587588 switch queryContext. query {
588589 case . executeStatement( _, let promise) , . unnamed( _, let promise) :
589590 return . failQuery( promise, with: psqlErrror, cleanupContext: nil )
590591 case . prepareStatement( _, _, _, let promise) :
591592 return . failPreparedStatementCreation( promise, with: psqlErrror, cleanupContext: nil )
592593 }
593- case . closeCommand( let closeContext) :
594+ case . closeCommand( let closeContext, let writePromise) :
595+ writePromise? . fail ( psqlErrror) /// Use `cleanupContext` or not?
594596 return . failClose( closeContext, with: psqlErrror, cleanupContext: nil )
595597 }
596598 }
@@ -934,17 +936,17 @@ struct ConnectionStateMachine {
934936 }
935937
936938 switch task {
937- case . extendedQuery( let queryContext) :
939+ case . extendedQuery( let queryContext, let promise ) :
938940 self . state = . modifying // avoid CoW
939941 var extendedQuery = ExtendedQueryStateMachine ( queryContext: queryContext)
940- let action = extendedQuery. start ( )
942+ let action = extendedQuery. start ( promise )
941943 self . state = . extendedQuery( extendedQuery, connectionContext)
942944 return self . modify ( with: action)
943945
944- case . closeCommand( let closeContext) :
946+ case . closeCommand( let closeContext, let promise ) :
945947 self . state = . modifying // avoid CoW
946948 var closeStateMachine = CloseStateMachine ( closeContext: closeContext)
947- let action = closeStateMachine. start ( )
949+ let action = closeStateMachine. start ( promise )
948950 self . state = . closeCommand( closeStateMachine, connectionContext)
949951 return self . modify ( with: action)
950952 }
@@ -1031,10 +1033,10 @@ extension ConnectionStateMachine {
10311033extension ConnectionStateMachine {
10321034 mutating func modify( with action: ExtendedQueryStateMachine . Action ) -> ConnectionStateMachine . ConnectionAction {
10331035 switch action {
1034- case . sendParseDescribeBindExecuteSync( let query) :
1035- return . sendParseDescribeBindExecuteSync( query)
1036- case . sendBindExecuteSync( let executeStatement) :
1037- return . sendBindExecuteSync( executeStatement)
1036+ case . sendParseDescribeBindExecuteSync( let query, let promise ) :
1037+ return . sendParseDescribeBindExecuteSync( query, promise : promise )
1038+ case . sendBindExecuteSync( let executeStatement, let promise ) :
1039+ return . sendBindExecuteSync( executeStatement, promise : promise )
10381040 case . failQuery( let requestContext, with: let error) :
10391041 let cleanupContext = self . setErrorAndCreateCleanupContextIfNeeded ( error)
10401042 return . failQuery( requestContext, with: error, cleanupContext: cleanupContext)
@@ -1057,8 +1059,8 @@ extension ConnectionStateMachine {
10571059 return . read
10581060 case . wait:
10591061 return . wait
1060- case . sendParseDescribeSync( name: let name, query: let query, bindingDataTypes: let bindingDataTypes) :
1061- return . sendParseDescribeSync( name: name, query: query, bindingDataTypes: bindingDataTypes)
1062+ case . sendParseDescribeSync( name: let name, query: let query, bindingDataTypes: let bindingDataTypes, let promise ) :
1063+ return . sendParseDescribeSync( name: name, query: query, bindingDataTypes: bindingDataTypes, promise : promise )
10621064 case . succeedPreparedStatementCreation( let promise, with: let rowDescription) :
10631065 return . succeedPreparedStatementCreation( promise, with: rowDescription)
10641066 case . failPreparedStatementCreation( let promise, with: let error) :
@@ -1094,8 +1096,8 @@ extension ConnectionStateMachine {
10941096extension ConnectionStateMachine {
10951097 mutating func modify( with action: CloseStateMachine . Action ) -> ConnectionStateMachine . ConnectionAction {
10961098 switch action {
1097- case . sendCloseSync( let sendClose) :
1098- return . sendCloseSync( sendClose)
1099+ case . sendCloseSync( let sendClose, let promise ) :
1100+ return . sendCloseSync( sendClose, promise : promise )
10991101 case . succeedClose( let closeContext) :
11001102 return . succeedClose( closeContext)
11011103 case . failClose( let closeContext, with: let error) :
0 commit comments