/* For each number in an array, an asynchronous timer lasting the
length of the number is set, printing the number once the timer is up.*/
const numbers = [1, 6, 3, 5, 4, 2]
numbers.forEach(num => {
setTimeout(() => console.log(num), num)
});
from time import sleep
from threading import Timer
def sleep_sort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
x = [3,2,4,7,3,6,9,1]
print sleep_sort(x)
#[1, 2, 3, 3, 4, 6, 7, 9]