Closed RonnyPfannschmidt closed 9 years ago
Hi Ronny,
What you want to do here is bind these parameters into the performers when you build your dispatcher.
Here, for example, given the same definitions of upgrade_progress
and do_something
from functools import partial
dispatcher = TypeDispatcher({
UpgradeProgress: partial(upgrade_progress, progress=SimpleProgressBarWithDbus()),
DoSomething: partial(do_something, context=Appcontext())
})
sync_perform(dispatcher, sequence(...))
You can also use a more Object Oriented technique (which is really just an unnecessarily verbose way of doing the same kind of partial
) like so:
class UpgradeProgressPerformer(object):
def __init__(self, progress):
self.progress = progress
@sync_performer
def upgrade_progress(self, dispatcher, intent):
if self.progress is not None:
return self.progress.update_from(intent)
upgrade_progress_performer = UpgradeProgressPerformer(progress)
dispatcher = TypeDispatcher({
UpgradeProgress: upgrade_progress_performer.upgrade_progress,
...
})
...
sync_perform(dispatcher, sequence(...))
Does this make sense?
then i would need some kind of composed dispatcher anyway, i'll have to experiment
in part i want to avod too many callbacks, and composition issues
Okay, I think this is resolved, please reopen if you think there's still a problem
in order to pass utilities to all performes that use thme i propose supporting passing kwargs to perform, and passing those as named arguments to performers, filtering those the performer does not take
strawman example to bootstrap discussion: