Search code examples
kdb

How can I make KDB sleep for 5 seconds?


I've got a rate-limited endpoint I'm querying, and so I need to make KDB pause between requests. Is there a way I can block the current thread?


Solution

  • The solutions using system are good for the majority of use cases. If you want an OS-agnostic method, the below lambda can be used, passing the time to wait as an argument:

    {t:.z.p;while[.z.p<t+x]} 00:00:05
    

    This approach can also be used if you're making these requests using secondary/slave threads (for example, using peach), whereas attempting to use the system keyword will fail in this case.