forked from ruppysuppy/Daily-Coding-Problem-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path010.py
More file actions
29 lines (19 loc) · 610 Bytes
/
010.py
File metadata and controls
29 lines (19 loc) · 610 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Problem:
Implement a job scheduler which takes in a function f and an integer n, and calls f
after n milliseconds.
"""
from time import sleep
from typing import Callable
def get_seconds_from_milliseconds(time_mil: int) -> float:
return time_mil / 1000
def job_scheduler(function: Callable, delay: int) -> None:
sleep(get_seconds_from_milliseconds(delay))
function()
# function to test the job scheduler
def print_hello() -> None:
print("Hello!")
if __name__ == "__main__":
job_scheduler(print_hello, 1)
job_scheduler(print_hello, 500)
job_scheduler(print_hello, 1000)