Skip to main content
The WebSocket Close command (Command Type: 9) signals the active WebSocket connection to perform a clean close. Place at the end of an onMessage chain to terminate the connection once the desired condition is met.

Command Type

Command Type ID: 9

Parameters

No parameters. This command takes no configuration.

Behavior and Edge Cases

  • It signals the connection to close cleanly; any frames already buffered are processed before the socket actually closes (the onClose hook then runs).
  • Calling it when there is no active connection is a safe no-op — it does nothing and raises no error. This means it is safe to place at the end of an onConnect or onMessage chain even if the socket has already closed.
  • After a close, the step publishes its current accumulated result once; a mid-flow (non-last) step uses this to capture a one-time snapshot and move on.

Usage Examples

Close After Receiving Target Data

Used at the end of an onMessage chain to stop the connection once desired data has been collected:

Common Use Cases

  • Single-Response Collection: Connect, receive one meaningful message, then close
  • Conditional Termination: Combined with If-Else, close only when a stopping condition is met