Skip to main content

sleep() Function

The sleep() function halts execution for the specified milliseconds.


kind: JsPolicy
name: ""
operations: ["CREATE"]
resources: ["pods"]
javascript: |
// you should usually never(!) sleep inside a webhook,
// however there might be situations where you need to wait for
// something to happen in the cluster, so this function exists
// remember you can use {cache: false} as well for get() and list()
// if you need timing critical webhooks
const before = new Date().getTime();
sleep(1000); // sleep for 1 second
print(`Slept for ${(new Date().getTime() - before)}`);