[Python-3000] upon

Antoine solipsis at pitrou.net
Fri Nov 17 11:26:59 CET 2006


> However, this special-case approach is flawed in this example, because
> its use is so narrow. If you think about it for a minute, you
> immediately start to imagine all of the things that 'upon' ought to deal
> with that it doesn't.
> For example, it has no way to deal with error
> callbacks;

Arguably you could write :

    # Create a callback timer
    alarm = Timer()
    alarm.SetDuration( 100, Timer.Milliseconds )

    upon alarm.success:
       print "It's time to get up, silly-head!"
    upon alarm.failure:
       print "The clock is broken, you can go back to bed"

(or @upon(alarm.success) for the suggested decorator equivalent)

Which would resolve to something like :

    def _cb():
       print "It's time to get up, silly-head!"
    alarm.success.__upon__(_cb)
    def _cb():
       print "The clock is broken, you can go back to bed"
    alarm.failure.__upon__(_cb)





More information about the Python-3000 mailing list