EventWriter
struct EventWriter
A writer for Server-Sent Events.
Implementions
Methods
new
pub fn new(pipe: Pipe): EventWriter
[src]
pub fn new(pipe: Pipe): EventWriter {
return EventWriter { pipe };
}
Creates a new EventWriter
with the given pipe.
new
pub fn new(pipe: Pipe): EventWriter
[src]
pub fn new(pipe: Pipe): EventWriter {
return EventWriter { pipe };
}
Creates a new EventWriter
with the given pipe.
Creates a new EventWriter
with the given pipe.
message
pub fn message(self, data: string, id: string? = nil, event: string = "message") throws IoError
[src]
pub fn message(self, data: string, id: string? = nil, event: string = "message") throws IoError {
if (let id = id) {
try self.pipe.write_string(`id: ${id}\n`);
}
if (!event.is_empty() && event != "message") {
try self.pipe.write_string(`event: ${event}\n`);
}
for (let line in data.split("\n")) {
try self.pipe.write_string(`data: ${line}\n`);
}
try self.pipe.write_string("\n");
}
Writes a message to the client.
message
pub fn message(self, data: string, id: string? = nil, event: string = "message") throws IoError
[src]
pub fn message(self, data: string, id: string? = nil, event: string = "message") throws IoError {
if (let id = id) {
try self.pipe.write_string(`id: ${id}\n`);
}
if (!event.is_empty() && event != "message") {
try self.pipe.write_string(`event: ${event}\n`);
}
for (let line in data.split("\n")) {
try self.pipe.write_string(`data: ${line}\n`);
}
try self.pipe.write_string("\n");
}
Writes a message to the client.
Writes a message to the client.
[src]
pub fn retry(self, duration: Duration) throws IoError {
try self.pipe.write_string(`retry: ${duration.milliseconds()}\n`);
try self.pipe.write_string("\n");
}
Writes a retry message to the client.
[src]
pub fn retry(self, duration: Duration) throws IoError {
try self.pipe.write_string(`retry: ${duration.milliseconds()}\n`);
try self.pipe.write_string("\n");
}
Writes a retry message to the client.
Writes a retry message to the client.
[src]
pub fn comment(self, comment: string) throws IoError {
if (comment.is_empty()) {
try self.pipe.write_string(":\n\n");
return;
}
for (let line in comment.split("\n")) {
try self.pipe.write_string(`: ${line}\n`);
}
try self.pipe.write_string("\n");
}
Writes a comment to the client.
[src]
pub fn comment(self, comment: string) throws IoError {
if (comment.is_empty()) {
try self.pipe.write_string(":\n\n");
return;
}
for (let line in comment.split("\n")) {
try self.pipe.write_string(`: ${line}\n`);
}
try self.pipe.write_string("\n");
}
Writes a comment to the client.
Writes a comment to the client.