Giter VIP home page Giter VIP logo

Comments (6)

abdolence avatar abdolence commented on May 18, 2024

Hey,
if you want to use your own lifecycle instead of serve, there is normal API with start().await and shutdown().await, so you can handle signals yourself and have other lifecycle you need.

serve is just a wrapping method created for convenience/examples.

from slack-morphism-rust.

Gremious avatar Gremious commented on May 18, 2024

Oh I just wanted to run it in main, and hit Ctrl-C to exit, nothing fancy. So just using serve for convenience.

Thing is, I also run a client/listener for a discord bot in the same app, so at least one of those 2 awaits nees to go into their own tokio task.

Sending a Ctrl-C while discord serenity's client is inisde a task is handled gracefuly, thankfully, so I just do that - but Morphism - not so much.

from slack-morphism-rust.

abdolence avatar abdolence commented on May 18, 2024

Yeah, as I suspected you have other stuff to run and await :)
You need to use

  1. slack.start().await <- this will be returned as soon as it is ready
  2. discord_client.start().await // Not sure if they're blocking thread or not
  3. your own handler for signals (you can use ctrlc yourself if you want)
  4. slack.shutdown().await <- to disconnect from Slack server for Socket Mode
  5. other cleanups (discord?)

from slack-morphism-rust.

abdolence avatar abdolence commented on May 18, 2024

The nature of an error is coming from the ctrlc implementation:
https://detegr.github.io/doc/ctrlc/fn.set_handler.html#

Should only be called once, typically at the start of your program

I suspect someone else already set it. I don't have a windows machine to debug it more, so if you are able to find a better implementation for windows, let me know :)

from slack-morphism-rust.

Gremious avatar Gremious commented on May 18, 2024

Ahh, thank you, your example actually makes the api a lot clearer. I (wasn't awake enough and) didn't read hard enough into it, so I had assumed I would've needed to setup events to send signals or some such, but it's just two split calls - appreciate it!

My qualms have been resolved (Thanks!), so I'll let you handle closing the issue in the hopes that a good ctrl-c lib that fixes this comes along ?

from slack-morphism-rust.

abdolence avatar abdolence commented on May 18, 2024

Well, if it works for you, then I'll close this issue, since as I mentioned, serve is just using ctrlc for Windows (if you look at the source code, it just 3-4 lines of code).
In real life application start/shutdown is a way to go.

from slack-morphism-rust.

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.