Code Monkey home page Code Monkey logo

Comments (8)

anderejd avatar anderejd commented on May 3, 2024 1

A callback on success would allow further actions, like launching an embedded browser to connect to the resulting listening port (if a port was picked by the system instead the Config).

from rocket.

mrkishi avatar mrkishi commented on May 3, 2024

Would a Rocket::launch() -> Result still block on success?

I ask because, if so, I'd suggest for a slightly lower-level interface to be exposed as well. That'd allow framework users to start tasks after successful binds, for instance.

We could keep launch but also expose optional separate bind and run loop methods, say, countdown and takeoff. Well, substituting those tongue-in-cheek names but you get the idea. πŸ˜„

Thoughts? Also, how could a Rust newbie help?

from rocket.

jkelin avatar jkelin commented on May 3, 2024

Yes, launch should block. It is consistent with how other web servers work (iron, nickel) and besides, how would we make it not block? Make Rocket run launch in a thread? That seems like it would create its own set of issues.

I like the idea of separating bind and run loop, if it would be possible to bind to multiple ports and addresses (possibly with different http/s combinations) and then handle connections from all with a single run loop, that would be amazing. However, I am not sure if it is even possible. AFAIK iron cannot do that, not sure if hyper can.

from rocket.

anderejd avatar anderejd commented on May 3, 2024

I ask because, if so, I'd suggest for a slightly lower-level interface to be exposed as well. That'd allow framework users to start tasks after successful binds, for instance.

This case is solved by #210 (still a work in progress)

from rocket.

SergioBenitez avatar SergioBenitez commented on May 3, 2024

I think we can be a tad-bit more clever here, but I agree. Let's get this in for 0.3.

from rocket.

mehcode avatar mehcode commented on May 3, 2024

An interesting hack would be to make ::launch() use a new thread to start the server and then .join() it in the Drop (which I think is default for rust's threads).

Your normal examples would all work the same but something like this would also work:

fn main() {
  // ignore the obvious port conflict here
  let _ = rocket::ignite().launch();
  let _ = rocket::ignite().launch();
}

Yes, launch should block. It is consistent with how other web servers work (iron, nickel) and besides, how would we make it not block?

Iron does not block. At least it doesn't in the current version. I'm guessing it uses a similar approach to what I say above.

from rocket.

SergioBenitez avatar SergioBenitez commented on May 3, 2024

Someone (maybe you?) proposed this, but it just feels like too much magic. I had in mind something much simpler: return a RocketError where RocketError implements Drop and simply prints the error out to the console. This exactly emulates the behavior we have right now, and the behavior most will want, while still letting someone catch it.

from rocket.

mehcode avatar mehcode commented on May 3, 2024

I can't imagine myself ever wanting multiple rocket servers running from the same main so don't want it that much. It's super easy to have N binaries in the same cargo project anyway.

I'm fine with the simpler option.

from rocket.

Related Issues (20)

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.