Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to process for operating system signals #209

Merged
merged 9 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ name = "dune"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[target.'cfg(unix)'.dependencies]
nix = { version = "0.28.0", features = ["signal"] }

[target.'cfg(windows)'.dependencies]
enable-ansi-support = "0.2.1"
[dependencies.dune_event_loop]
git = "https://github.com/aalykiot/dune-event-loop"
branch = "main"

[dependencies]
v8 = { version = "0.89.0", default-features = false }
Expand Down Expand Up @@ -66,5 +64,11 @@ tokio = { version = "1.37.0", features = ["full"] }
axum = { version = "0.7.5", features = ["ws"] }
uuid = { version = "1.8.0", features = ["v4", "fast-rng"] }

[target.'cfg(unix)'.dependencies]
nix = { version = "0.28.0", features = ["signal"] }

[target.'cfg(windows)'.dependencies]
enable-ansi-support = "0.2.1"

[dev-dependencies]
assert_fs = "1.1.1"
17 changes: 17 additions & 0 deletions examples/signals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import http from 'http';

// We need somehow to keep the event-loop alive.
http.createServer(() => {}).listen(3000);

let shouldExit = false;

// Exit on fast double CTRL+C key press.
const onSignal = () => {
if (shouldExit) process.exit(0);
shouldExit = true;
setTimeout(() => {
shouldExit = false;
}, 500);
};

process.on('SIGINT', onSignal);
2 changes: 2 additions & 0 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::net;
use crate::perf_hooks;
use crate::process;
use crate::promise;
use crate::signals;
use crate::stdio;
use crate::timers;
use anyhow::Error;
Expand All @@ -28,6 +29,7 @@ lazy_static! {
("net", net::initialize),
("promise", promise::initialize),
("http_parser", http_parser::initialize),
("signals", signals::initialize),
];
HashMap::from_iter(bindings.into_iter())
};
Expand Down
4 changes: 2 additions & 2 deletions src/dns.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::bindings::set_exception_code;
use crate::bindings::set_function_to;
use crate::bindings::set_property_to;
use crate::event_loop::LoopHandle;
use crate::event_loop::TaskResult;
use crate::runtime::JsFuture;
use crate::runtime::JsRuntime;
use anyhow::Result;
use dns_lookup::lookup_host;
use dune_event_loop::LoopHandle;
use dune_event_loop::TaskResult;
use std::net::IpAddr;

pub fn initialize(scope: &mut v8::HandleScope) -> v8::Global<v8::Object> {
Expand Down
Loading
Loading