Add delay

This commit is contained in:
Angelos Chalaris
2020-01-02 16:24:51 +02:00
parent 2973799a7d
commit 038ed366c1

24
snippets/delay.md Normal file
View File

@ -0,0 +1,24 @@
---
title: delay
tags: function,intermediate
---
Invokes the provided function after `ms` milliseconds.
Use `sleep()` to delay the execution of `fn` by `ms / 1000` seconds.
```py
from time import sleep
def delay(fn, ms, *args):
sleep(ms / 1000)
return fn(*args)
```
```py
delay(
lambda x: print(x),
1000,
'later'
) # prints 'later' after one second
```