@@ -72,27 +72,44 @@ private void generateWaiter() {
72
72
writer .addImport ("createWaiter" , "createWaiter" , WAITABLE_UTIL_PACKAGE );
73
73
writer .addImport ("WaiterResult" , "WaiterResult" , WAITABLE_UTIL_PACKAGE );
74
74
writer .addImport ("WaiterState" , "WaiterState" , WAITABLE_UTIL_PACKAGE );
75
+ writer .addImport ("checkExceptions" , "checkExceptions" , WAITABLE_UTIL_PACKAGE );
75
76
writer .addImport ("WaiterConfiguration" , "WaiterConfiguration" , WAITABLE_UTIL_PACKAGE );
76
77
78
+ // generates (deprecated) WaitFor....
77
79
writer .writeDocs (waiter .getDocumentation ().orElse ("" ) + " \n "
78
- + " @param params : Waiter configuration options. \n "
79
- + " @param input : the input to " + operationSymbol . getName () + " for polling ." );
80
+ + " @deprecated Use waitUntil" + waiterName + " instead. "
81
+ + "waitFor" + waiterName + " does not throw error in non-success cases ." );
80
82
writer .openBlock ("export const waitFor$L = async (params: WaiterConfiguration<$T>, input: $T): "
81
83
+ "Promise<WaiterResult> => {" , "}" , waiterName , serviceSymbol , inputSymbol , () -> {
82
84
writer .write ("const serviceDefaults = { minDelay: $L, maxDelay: $L };" , waiter .getMinDelay (),
83
85
waiter .getMaxDelay ());
84
86
writer .write ("return createWaiter({...serviceDefaults, ...params}, input, checkState);" );
85
87
});
88
+
89
+ // generates WaitUtil....
90
+ writer .writeDocs (waiter .getDocumentation ().orElse ("" ) + " \n "
91
+ + " @param params - Waiter configuration options.\n "
92
+ + " @param input - The input to " + operationSymbol .getName () + " for polling." );
93
+ writer .openBlock ("export const waitUntil$L = async (params: WaiterConfiguration<$T>, input: $T): "
94
+ + "Promise<WaiterResult> => {" , "}" , waiterName , serviceSymbol , inputSymbol , () -> {
95
+ writer .write ("const serviceDefaults = { minDelay: $L, maxDelay: $L };" , waiter .getMinDelay (),
96
+ waiter .getMaxDelay ());
97
+ writer .write ("const result = await createWaiter({...serviceDefaults, ...params}, input, checkState);" );
98
+ writer .write ("return checkExceptions(result);" );
99
+ });
86
100
}
87
101
88
102
private void generateAcceptors () {
89
103
writer .openBlock ("const checkState = async (client: $T, input: $T): Promise<WaiterResult> => {" , "}" ,
90
104
serviceSymbol , inputSymbol , () -> {
105
+ writer .write ("let reason;" );
91
106
writer .openBlock ("try {" , "}" , () -> {
92
107
writer .write ("let result: any = await client.send(new $T(input))" , operationSymbol );
108
+ writer .write ("reason = result;" );
93
109
writeAcceptors ("result" , false );
94
110
});
95
111
writer .openBlock ("catch (exception) {" , "}" , () -> {
112
+ writer .write ("reason = exception;" );
96
113
writeAcceptors ("exception" , true );
97
114
});
98
115
writer .write ("return $L;" , makeWaiterResult (AcceptorState .RETRY ));
@@ -167,11 +184,11 @@ private void generatePathMatcher(String accessor, PathMatcher pathMatcher, Accep
167
184
168
185
private String makeWaiterResult (AcceptorState resultantState ) {
169
186
if (resultantState == AcceptorState .SUCCESS ) {
170
- return "{ state: WaiterState.SUCCESS }" ;
187
+ return "{ state: WaiterState.SUCCESS, reason }" ;
171
188
} else if (resultantState == AcceptorState .FAILURE ) {
172
- return "{ state: WaiterState.FAILURE }" ;
189
+ return "{ state: WaiterState.FAILURE, reason }" ;
173
190
} else if (resultantState == AcceptorState .RETRY ) {
174
- return "{ state: WaiterState.RETRY }" ;
191
+ return "{ state: WaiterState.RETRY, reason }" ;
175
192
}
176
193
throw new CodegenException ("Hit an invalid acceptor state to codegen " + resultantState .toString ());
177
194
}
0 commit comments