@@ -85,8 +85,8 @@ struct ConnectionStateMachine {
85
85
// Connection Actions
86
86
87
87
// --- general actions
88
- case sendParseDescribeBindExecuteSync( PostgresQuery )
89
- case sendBindExecuteSync( PSQLExecuteStatement )
88
+ case sendParseDescribeBindExecuteSync( PostgresQuery , promise : EventLoopPromise < Void > ? )
89
+ case sendBindExecuteSync( PSQLExecuteStatement , promise : EventLoopPromise < Void > ? )
90
90
case failQuery( EventLoopPromise < PSQLRowStream > , with: PSQLError , cleanupContext: CleanUpContext ? )
91
91
case succeedQuery( EventLoopPromise < PSQLRowStream > , with: QueryResult )
92
92
@@ -97,12 +97,12 @@ struct ConnectionStateMachine {
97
97
case forwardStreamError( PSQLError , read: Bool , cleanupContext: CleanUpContext ? )
98
98
99
99
// Prepare statement actions
100
- case sendParseDescribeSync( name: String , query: String , bindingDataTypes: [ PostgresDataType ] )
100
+ case sendParseDescribeSync( name: String , query: String , bindingDataTypes: [ PostgresDataType ] , promise : EventLoopPromise < Void > ? )
101
101
case succeedPreparedStatementCreation( EventLoopPromise < RowDescription ? > , with: RowDescription ? )
102
102
case failPreparedStatementCreation( EventLoopPromise < RowDescription ? > , with: PSQLError , cleanupContext: CleanUpContext ? )
103
103
104
104
// Close actions
105
- case sendCloseSync( CloseTarget )
105
+ case sendCloseSync( CloseTarget , promise : EventLoopPromise < Void > ? )
106
106
case succeedClose( CloseCommandContext )
107
107
case failClose( CloseCommandContext , with: PSQLError , cleanupContext: CleanUpContext ? )
108
108
}
@@ -234,7 +234,7 @@ struct ConnectionStateMachine {
234
234
}
235
235
self . state = . sslNegotiated
236
236
return . establishSSLConnection
237
-
237
+
238
238
case . initialized,
239
239
. sslNegotiated,
240
240
. sslHandlerAdded,
@@ -247,7 +247,7 @@ struct ConnectionStateMachine {
247
247
. closing,
248
248
. closed:
249
249
return self . closeConnectionAndCleanup ( . unexpectedBackendMessage( . sslSupported) )
250
-
250
+
251
251
case . modifying:
252
252
preconditionFailure ( " Invalid state: \( self . state) " )
253
253
}
@@ -583,14 +583,16 @@ struct ConnectionStateMachine {
583
583
}
584
584
585
585
switch task {
586
- case . extendedQuery( let queryContext) :
586
+ case . extendedQuery( let queryContext, let writePromise) :
587
+ writePromise? . fail ( psqlErrror) /// Use `cleanupContext` or not?
587
588
switch queryContext. query {
588
589
case . executeStatement( _, let promise) , . unnamed( _, let promise) :
589
590
return . failQuery( promise, with: psqlErrror, cleanupContext: nil )
590
591
case . prepareStatement( _, _, _, let promise) :
591
592
return . failPreparedStatementCreation( promise, with: psqlErrror, cleanupContext: nil )
592
593
}
593
- case . closeCommand( let closeContext) :
594
+ case . closeCommand( let closeContext, let writePromise) :
595
+ writePromise? . fail ( psqlErrror) /// Use `cleanupContext` or not?
594
596
return . failClose( closeContext, with: psqlErrror, cleanupContext: nil )
595
597
}
596
598
}
@@ -934,17 +936,17 @@ struct ConnectionStateMachine {
934
936
}
935
937
936
938
switch task {
937
- case . extendedQuery( let queryContext) :
939
+ case . extendedQuery( let queryContext, let promise ) :
938
940
self . state = . modifying // avoid CoW
939
941
var extendedQuery = ExtendedQueryStateMachine ( queryContext: queryContext)
940
- let action = extendedQuery. start ( )
942
+ let action = extendedQuery. start ( promise )
941
943
self . state = . extendedQuery( extendedQuery, connectionContext)
942
944
return self . modify ( with: action)
943
945
944
- case . closeCommand( let closeContext) :
946
+ case . closeCommand( let closeContext, let promise ) :
945
947
self . state = . modifying // avoid CoW
946
948
var closeStateMachine = CloseStateMachine ( closeContext: closeContext)
947
- let action = closeStateMachine. start ( )
949
+ let action = closeStateMachine. start ( promise )
948
950
self . state = . closeCommand( closeStateMachine, connectionContext)
949
951
return self . modify ( with: action)
950
952
}
@@ -1031,10 +1033,10 @@ extension ConnectionStateMachine {
1031
1033
extension ConnectionStateMachine {
1032
1034
mutating func modify( with action: ExtendedQueryStateMachine . Action ) -> ConnectionStateMachine . ConnectionAction {
1033
1035
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 )
1038
1040
case . failQuery( let requestContext, with: let error) :
1039
1041
let cleanupContext = self . setErrorAndCreateCleanupContextIfNeeded ( error)
1040
1042
return . failQuery( requestContext, with: error, cleanupContext: cleanupContext)
@@ -1057,8 +1059,8 @@ extension ConnectionStateMachine {
1057
1059
return . read
1058
1060
case . wait:
1059
1061
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 )
1062
1064
case . succeedPreparedStatementCreation( let promise, with: let rowDescription) :
1063
1065
return . succeedPreparedStatementCreation( promise, with: rowDescription)
1064
1066
case . failPreparedStatementCreation( let promise, with: let error) :
@@ -1094,8 +1096,8 @@ extension ConnectionStateMachine {
1094
1096
extension ConnectionStateMachine {
1095
1097
mutating func modify( with action: CloseStateMachine . Action ) -> ConnectionStateMachine . ConnectionAction {
1096
1098
switch action {
1097
- case . sendCloseSync( let sendClose) :
1098
- return . sendCloseSync( sendClose)
1099
+ case . sendCloseSync( let sendClose, let promise ) :
1100
+ return . sendCloseSync( sendClose, promise : promise )
1099
1101
case . succeedClose( let closeContext) :
1100
1102
return . succeedClose( closeContext)
1101
1103
case . failClose( let closeContext, with: let error) :
0 commit comments