@@ -29,14 +29,6 @@ export interface Invocation {
2929 retry ( retryCount : number ) : Promise < void > ;
3030}
3131
32- /**
33- * Signature of a function that fetches a single output. Used by `pollForOutputs` to fetch from either
34- * the control plane or the input plane, depending on the implementation.
35- */
36- type GetOutput = (
37- timeoutMillis : number ,
38- ) => Promise < FunctionGetOutputsItem | undefined > ;
39-
4032/**
4133 * Implementation of Invocation which sends inputs to the control plane.
4234 */
@@ -97,19 +89,15 @@ export class ControlPlaneInvocation implements Invocation {
9789 async #getOutput(
9890 timeoutMillis : number ,
9991 ) : Promise < FunctionGetOutputsItem | undefined > {
100- try {
101- const response = await client . functionGetOutputs ( {
102- functionCallId : this . functionCallId ,
103- maxValues : 1 ,
104- timeout : timeoutMillis / 1000 , // Backend needs seconds
105- lastEntryId : "0-0" ,
106- clearOnSuccess : true ,
107- requestedAt : timeNowSeconds ( ) ,
108- } ) ;
109- return response . outputs ? response . outputs [ 0 ] : undefined ;
110- } catch ( err ) {
111- throw new Error ( `FunctionGetOutputs failed: ${ err } ` ) ;
112- }
92+ const response = await client . functionGetOutputs ( {
93+ functionCallId : this . functionCallId ,
94+ maxValues : 1 ,
95+ timeout : timeoutMillis / 1000 , // Backend needs seconds
96+ lastEntryId : "0-0" ,
97+ clearOnSuccess : true ,
98+ requestedAt : timeNowSeconds ( ) ,
99+ } ) ;
100+ return response . outputs ? response . outputs [ 0 ] : undefined ;
113101 }
114102
115103 async retry ( retryCount : number ) : Promise < void > {
@@ -212,6 +200,19 @@ function timeNowSeconds() {
212200 return Date . now ( ) / 1e3 ;
213201}
214202
203+ /**
204+ * Signature of a function that fetches a single output using the given timeout. Used by `pollForOutputs` to fetch
205+ * from either the control plane or the input plane, depending on the implementation.
206+ */
207+ type GetOutput = (
208+ timeoutMillis : number ,
209+ ) => Promise < FunctionGetOutputsItem | undefined > ;
210+
211+ /***
212+ * Repeatedly tries to fetch an output using the provided `getOutput` function, and the specified timeout value.
213+ * We use a timeout value of 55 seconds if the caller does not specify a timeout value, or if the specified timeout
214+ * value is greater than 55 seconds.
215+ */
215216async function pollFunctionOutput (
216217 getOutput : GetOutput ,
217218 timeout ?: number , // in milliseconds
0 commit comments