diff options
| author | Andreas Grois <andi@grois.info> | 2022-10-10 21:30:02 +0200 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2022-10-10 21:37:15 +0200 |
| commit | e4ad766315879e1ff05bb111229f073f8f0ed68e (patch) | |
| tree | 4b043ff47c78b2c00c80c94ebda622c32c8b6d3d /rust/src/implementation/passwordmaker/emittingsender.rs | |
PassFish: Initial Commit
Well, that's a lie. But nobody needs to see all the iterations I decided
to sweep under the rug.
That said, I think the repo is, while not clean, clean enough now, to
not be embarrassed by uploading it to github.
Diffstat (limited to 'rust/src/implementation/passwordmaker/emittingsender.rs')
| -rw-r--r-- | rust/src/implementation/passwordmaker/emittingsender.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/rust/src/implementation/passwordmaker/emittingsender.rs b/rust/src/implementation/passwordmaker/emittingsender.rs new file mode 100644 index 0000000..1cf58fc --- /dev/null +++ b/rust/src/implementation/passwordmaker/emittingsender.rs @@ -0,0 +1,17 @@ +use std::sync::mpsc::{channel,Sender,Receiver,SendError}; +#[derive(Clone)] +pub(crate) struct EmittingSender<MT, E : Fn()> { + sender : Sender<MT>, + emit : E, +} + +impl <MT, E : Fn()> EmittingSender<MT, E>{ + pub(crate) fn emitting_channel(emit : E) -> (Self, Receiver<MT>) { + let (sender,r) = channel(); + (EmittingSender { sender, emit }, r) + } + pub(crate) fn send(&self, t: MT) -> Result<(), SendError<MT>> { + //first send, then notify. + self.sender.send(t).map(|_| (self.emit)()) + } +} |
