Delayed function execution

Python, Function · Nov 2, 2020

Invokes the provided function after ms milliseconds.

  • Use time.sleep() to delay the execution of fn by ms / 1000 seconds.
from time import sleep

def delay(fn, ms, *args):
  sleep(ms / 1000)
  return fn(*args)
delay(lambda x: print(x), 1000, 'later') # prints 'later' after one second

More like this

  • Check property

    Creates a function that will invoke a predicate function for the specified property on a given dictionary.

    Python, Function · Nov 2, 2020

  • Unfold list

    Builds a list, using an iterator function and an initial seed value.

    Python, Function · Nov 2, 2020

  • Compose functions

    Performs right-to-left function composition.

    Python, Function · Nov 2, 2020