This topic was automatically generated from Slack. You can find the original thread here.
I have this workflow but get “$.respond() not called for this invocation” as error:
Trigger
a. Setting: “Return a custom response from your workflow”
Delay on 10 seconds
Reponse:
a. status: 200
b. headers{0}body:hello world!
Works fine in testing but postman get an error. I want pipedream to force to wait for the reponse.
Since the delay step suspends the execution of your workflow, you can’t delay and then return an HTTP response synchronously. @U05A7KLNALC can you rewrite the delay step above by awaiting a Promise on a setTimeout for 10 seconds?
Sure, you can use a Promise with a setTimeout to create a delay in your code. Here’s how you can do it: export default { name: "delayedResponse", type: "http", version: "0.0.1", props: { http: "$.interface.http", }, async run({ $ }) { // Create a new promise that resolves after a 10 second delay await new Promise((resolve) => setTimeout(resolve, 10000)); // Send the HTTP response this.http.respond({ status: 200, headers: { "Content-Type": "text/plain", }, body: "Hello, world!", }); }, }; This code creates a new Promise that resolves after a 10 second delay. The await keyword causes the function to pause and wait for the Promise to resolve before continuing. After the delay, the function sends the HTTP response.