nevalang / neva

🌊 Dataflow programming language with static types and implicit parallelism. Compiles to machine code and Go
https://nevalang.org
MIT License
124 stars 7 forks source link

Graceful shutdown for runtime #708

Open emil14 opened 1 month ago

emil14 commented 1 month ago

When we click ctrl+c we terminate the neva process without handling it. What we probably should do is to close the context to make sure func-runner is gracefully terminated. It's possible to imagine a situation where some component (e.g. http get) opens a connection and never frees it after ctrl+c (or other termination signals from the OS)

Question is, shouldn't user do these kind of things manually? Why e.g. Go doesn't handle resource freeing automatically?

emil14 commented 1 month ago
    // graceful shutdown for runtime
    ctx, cancel := context.WithCancel(context.Background())

    sigChan := make(chan os.Signal, 1)
    signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)

    go func() {
        <-sigChan
        cancel()
    }()