sender.rs 586 B

12345678910111213141516171819202122232425
  1. use allo_isolate::Isolate;
  2. use bytes::Bytes;
  3. use flowy_notification::entities::SubscribeObject;
  4. use flowy_notification::NotificationSender;
  5. use std::convert::TryInto;
  6. pub struct DartNotificationSender {
  7. isolate: Isolate,
  8. }
  9. impl DartNotificationSender {
  10. pub fn new(port: i64) -> Self {
  11. Self {
  12. isolate: Isolate::new(port),
  13. }
  14. }
  15. }
  16. impl NotificationSender for DartNotificationSender {
  17. fn send_subject(&self, subject: SubscribeObject) -> Result<(), String> {
  18. let bytes: Bytes = subject.try_into().unwrap();
  19. self.isolate.post(bytes.to_vec());
  20. Ok(())
  21. }
  22. }