2020-10-15 22:49:05

Hi all,
I know it's only been a day since I posted, but this has been a plan on my mind for a while, and the new Earwax promises framework gave me the ability to bring MOO-style suspends into Python.

For those of you who don't know, when you're coding using the MOO programming language, you have 2 ways of temporarily suspending a function:

player.tell("Hello there.");
player.tell("That took a while.");
  player.tell("That took even longer.");

It's been a while since I coded in MOO, but you get the idea.

With Python's generators, you can kind of simulate that behaviour, which is what the new StaggeredPromise class lets you do with earwax:

from earwax import StaggeredPromise
from earwax.types import StaggeredPromiseGeneratorType

def promise() -> StaggeredPromiseGeneratorType:
    game.output('Hello world.')
    yield 2.0
    game.output('That took a while.')
    yield 5.0
    game.output('That took even longer.')


As with ThreadedPromise, you can catch the return value, and any raised errors. You can also get notified every time a promise suspends:

def on_next(delay: float) -> None:

I hope you enjoy using the StaggeredPromise class for splitting up your games a little, without messing about with any of Pyglet's schedule functions.

Also, sorry for the silly name... It's the best of the bad bunch I could come up with.

Take care,
Chris Norman
Selling my soul to andertons.co.uk since 2012.