-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed problem with no thread avaliability & made SSE spec compliant
- Loading branch information
1 parent
e266b8a
commit 1ae8e9b
Showing
7 changed files
with
268 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use actix_web::web::Bytes; | ||
|
||
pub(crate) struct Event<T : EventTrait> { | ||
val: T | ||
} | ||
|
||
pub(crate) trait EventTrait { | ||
fn get_id(&self) -> Option<&'static str> { | ||
None | ||
} | ||
fn get_event(&self) -> Option<&'static str> { | ||
None | ||
} | ||
fn get_data(&self) -> Option<&'static str> { | ||
None | ||
} | ||
} | ||
|
||
impl<T: EventTrait> Event<T> { | ||
pub fn new(val: T) -> Self { | ||
Event { val } | ||
} | ||
} | ||
|
||
impl<T : EventTrait> ToString for Event<T> { | ||
fn to_string(&self) -> String { | ||
let mut output = "".to_string(); | ||
|
||
if let Some(value) = self.val.get_id() { | ||
output += &format!("id: {}\n", value); | ||
} | ||
if let Some(value) = self.val.get_event() { | ||
output += &format!("event: {}\n", value); | ||
} | ||
if let Some(value) = self.val.get_data() { | ||
output += &format!("data: {}\n", value); | ||
} | ||
|
||
if output != "" { | ||
output += "\n"; | ||
} | ||
|
||
return output; | ||
} | ||
} | ||
|
||
impl<T: EventTrait> Into<Bytes> for Event<T> { | ||
fn into(self) -> Bytes { | ||
Bytes::from(self.to_string()) | ||
} | ||
} | ||
|
||
impl<T: EventTrait> From<T> for Event<T> { | ||
fn from(value: T) -> Self { | ||
Event { val: value } | ||
} | ||
} | ||
|
||
pub(crate) struct EventBuilder { | ||
id: Option<&'static str>, | ||
event: Option<&'static str>, | ||
data: Option<&'static str>, | ||
} | ||
|
||
impl EventBuilder { | ||
pub fn new() -> Self { | ||
EventBuilder { id: None, event: None, data: None } | ||
} | ||
pub fn with_id(mut self, id: &'static str) -> Self { | ||
self.id = Some(id); | ||
self | ||
} | ||
pub fn with_event(mut self, event: &'static str) -> Self { | ||
self.event = Some(event); | ||
self | ||
} | ||
pub fn with_data(mut self, data: &'static str) -> Self { | ||
self.data = Some(data); | ||
self | ||
} | ||
} | ||
|
||
impl EventTrait for EventBuilder { | ||
fn get_data(&self) -> Option<&'static str> { | ||
self.data | ||
} | ||
fn get_event(&self) -> Option<&'static str> { | ||
self.event | ||
} | ||
fn get_id(&self) -> Option<&'static str> { | ||
self.id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.