HPInc / HP-Digital-Microfluidics

HP Digital Microfluidics Software Platform and Libraries
MIT License
3 stars 1 forks source link

`Barrier` doesn't need to be generic #285

Closed EvanKirshenbaum closed 10 months ago

EvanKirshenbaum commented 10 months ago

The Barrier class is currently defined as Barrier[T]:

class Barrier(Trigger, Generic[T]):
    def reach(self, val: T, future: Optional[Postable[T]] = None) -> int: ...
    def pause(self, val: T, future: Postable[T]) -> int:
    def pass_through(self, val: T) -> int:

None of its state, however, is dependent on its generic parameter T, and the val parameter to .pass_through() is essentially ignored, so it could probably be more simply defined as something like

class Barrier(Trigger):
    def reach(self, action: Optional[Union[tuple[T, Postable[T]], Callback]] = None) -> int: ...
    def pause(self, val: T, future: Postable[T]) -> int:
    def pass_through(self) -> int:

T would still be used in .reach() (optinally) and .pause() to ensure that the value was something passable to the future, but you could mix and match. Essentially,

b.pause(obj, future)

would simply be shorthand for

b.reach(lambda : future.post(obj))

(except that it would bind the values rather than referring to the variables.)

This will help with barriers in DML (#284) since otherwise I'll either have to make them a meta-type or they'd have to be Barrier[Any] inside, and that would require the future to be a Postable[Any], which would get messy.

Migrated from internal repository. Originally created by @EvanKirshenbaum on Jul 03, 2023 at 5:42 PM PDT. Closed on Jul 05, 2023 at 10:38 AM PDT.
EvanKirshenbaum commented 10 months ago

This issue was referenced by the following commit before migration:

EvanKirshenbaum commented 10 months ago

While I was there, I also changed Trigger to keep a list of callbacks rather than a list of object/future pairs, since it makes more sense to turn (val, future) into lambda: future.post(val) than to create a Postable[None] and hang calling the callback off of it.

Migrated from internal repository. Originally created by @EvanKirshenbaum on Jul 05, 2023 at 10:38 AM PDT.