Skip to content

Instantly share code, notes, and snippets.

@diverru
Created November 23, 2019 20:10
Show Gist options
  • Save diverru/3b317313366311fc260707cc91e77994 to your computer and use it in GitHub Desktop.
Save diverru/3b317313366311fc260707cc91e77994 to your computer and use it in GitHub Desktop.
promise fuckups
from promise import Promise
from threading import Thread
import threading
import time
import functools
def on_resolve(issued_by, fn):
name = threading.current_thread().getName()
if issued_by != name:
print(issued_by, name)
def worker():
my_name = threading.current_thread().getName()
now = time.time()
while now + 5 > time.time():
promise = Promise.resolve(None)
promise.then(functools.partial(on_resolve, my_name))
#time.sleep(0.001)
threads = []
for i in range(3):
threads.append(Thread(target=worker))
for thread in threads:
thread.start()
for thread in threads:
thread.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment