The problem
Any asynchronous code within a Node.js code step must complete before the next step runs. This ensures future steps have access to its data. If Pipedream detects that code is still running by the time the step completes, you’ll see the following warning below the code step:This step was still trying to run code when the step ended. Make sure you await all Promises, or promisify callback functions.As the warning notes, this often arises from one of two issues:
- You forgot to
await
a Promise. All Promises must be awaited within a step so they resolve before the step finishes. - You tried to run a callback function. Since callback functions run asynchronously, they typically will not finish before the step ends. You can wrap your function in a Promise to make sure it resolves before the step finishes.
Solutions
await
all Promises
Most Node.js packages that run async code return Promises as the result of method calls. For example, axios
is an HTTP client. If you make an HTTP request like this in a Pipedream code step:
axios
returns a Promise. Instead, add an await
in front of the call to axios
:
Wrap callback functions in a Promise
Before support for Promises was widespread, callback functions were a popular way to run some code asynchronously, after some operation was completed. For example, PDFKit lets you pass a callback function that runs when certain events fire, like when the PDF has been finalized:util.promisify
function.
Other solutions
If a specific library doesn’t support Promises, you can often find an equivalent library that does. For example, many older HTTP clients likerequest
didn’t support Promises natively, but the community published packages that wrapped it with a Promise-based interface (note: request
has been deprecated, this is just an example).