Code Monkey home page Code Monkey logo

async-sse's Issues

Use async-channel

#3 adds support for detecting disconnections through a custom Arc<AtomicBool>. This is not particularly efficient, but it works.

https://docs.rs/async-channel/1.1.1/async_channel/'s channels have a Sender that returns an error on disconnect; exactly as we would expect here. We should use this instead of our custom AtomicBool impl. async-std is expected to move over to this as well in the near future, but we shouldn't wait for that.

@jbr could you pick this up?

Error with `pin-project-lite:0.1.9`

Seeing the following error after running pin-project-lite released version 0.1.9.

error[E0453]: allow(explicit_outlives_requirements) overruled by outer forbid(rust_2018_idioms)
  --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/async-sse-4.0.0/src/encoder.rs:9:1
   |
9  | / pin_project_lite::pin_project! {
10 | |     /// An SSE protocol encoder.
11 | |     #[derive(Debug)]
12 | |     pub struct Encoder {
...  |
17 | |     }
18 | | }
   | |_^ overruled by previous forbid
   | 
  ::: /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/async-sse-4.0.0/src/lib.rs:34:11
   |
34 |   #![forbid(rust_2018_idioms)]
   |             ---------------- `forbid` level set here
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0453]: allow(explicit_outlives_requirements) overruled by outer forbid(rust_2018_idioms)
  --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/async-sse-4.0.0/src/lines.rs:11:1
   |
11 | / pin_project! {
12 | |     /// A stream of lines in a byte stream.
13 | |     ///
14 | |     /// This stream is created by the [`lines`] method on types that implement [`BufRead`].
...  |
28 | |     }
29 | | }
   | |_^ overruled by previous forbid
   | 
  ::: /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/async-sse-4.0.0/src/lib.rs:34:11
   |
34 |   #![forbid(rust_2018_idioms)]
   |             ---------------- `forbid` level set here
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Please support events without event names

The server-sent events standard does not require the event field. I'd like to be able to send events with no event field.

I can think of several possible ways to do this:

  • Modify the send method to take an Option<&str>. This would be the simplest to implement, but would necessitate a major version bump, and would require passing Some("name") when providing an event name, which may be inconvenient for the common case.
  • Add a new method that omits the argument for the event name. This would be backwards-compatible, but would require a more cumbersome method name when sending data-only events.
  • Add a new method taking an Option<&str>, and keep the existing method as a convenience wrapper.

I'd be happy to provide the implementation. Which approach would you prefer?

Encoder can possibly send duplicate bytes

Hello, I was reading through the Encoder's AsyncRead impl:

async-sse/src/encoder.rs

Lines 40 to 52 in 50db988

// Write the current buffer to completion.
let local_buf = self.buf.as_mut().unwrap();
let local_len = local_buf.len();
let max = buf.len().min(local_buf.len());
buf[..max].clone_from_slice(&local_buf[..max]);
self.cursor += max;
// Reset values if we're done reading.
if self.cursor == local_len {
self.buf = None;
self.cursor = 0;
};

I noticed that self.cursor wasn't being used to slice local_buf. So, it might be possible to copy the same section of local_buf multiple times.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.