{"id":13466065,"url":"https://github.com/Kitura/BlueSignals","last_synced_at":"2025-03-25T21:31:08.664Z","repository":{"id":43304606,"uuid":"54987470","full_name":"Kitura/BlueSignals","owner":"Kitura","description":"Generic Cross Platform Signal Handler","archived":false,"fork":false,"pushed_at":"2023-02-12T06:38:32.000Z","size":96,"stargazers_count":96,"open_issues_count":1,"forks_count":21,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-01T02:49:43.436Z","etag":null,"topics":["linux","macos","signals-default-handler","swift","trap-handler","trap-multiple-signals"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kitura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-03-29T15:29:05.000Z","updated_at":"2025-02-27T05:10:42.000Z","dependencies_parsed_at":"2023-11-23T22:32:05.009Z","dependency_job_id":"76377e08-4fc2-4e75-aaf1-7617376f6bf0","html_url":"https://github.com/Kitura/BlueSignals","commit_stats":{"total_commits":162,"total_committers":12,"mean_commits":13.5,"dds":0.5061728395061729,"last_synced_commit":"a5ce52795af4d91b3ff5dfb484ee3e45d9ed3d44"},"previous_names":["ibm-swift/bluesignals"],"tags_count":97,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FBlueSignals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FBlueSignals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FBlueSignals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FBlueSignals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kitura","download_url":"https://codeload.github.com/Kitura/BlueSignals/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245547206,"owners_count":20633322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux","macos","signals-default-handler","swift","trap-handler","trap-multiple-signals"],"created_at":"2024-07-31T15:00:38.773Z","updated_at":"2025-03-25T21:31:08.407Z","avatar_url":"https://github.com/Kitura.png","language":"Swift","readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.kitura.io/packages.html#all\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/docs-kitura.io-1FBCE4.svg\" alt=\"APIDoc\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://travis-ci.org/Kitura/BlueSignals\"\u003e\n    \u003cimg src=\"https://travis-ci.org/Kitura/BlueSignals.svg?branch=master\" alt=\"Build Status - Master\"\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/os-macOS-green.svg?style=flat\" alt=\"macOS\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/os-iOS-green.svg?style=flat\" alt=\"iOS\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/os-linux-green.svg?style=flat\" alt=\"Linux\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-Apache2-blue.svg?style=flat\" alt=\"Apache 2\"\u003e\n    \u003ca href=\"http://swift-at-ibm-slack.mybluemix.net/\"\u003e\n    \u003cimg src=\"http://swift-at-ibm-slack.mybluemix.net/badge.svg\" alt=\"Slack Status\"\u003e\n    \u003c/a\u003e\n\u003cp\u003e\n\n# Signals\n\nGeneric Cross Platform Signal Handler.\n\n## Prerequisites\n\n### Swift\n\n* Swift Open Source `swift-5.1-RELEASE` toolchain (**Minimum REQUIRED for latest release**)\n* Swift Open Source `swift-5.4-RELEASE` toolchain (**Recommended**)\n* Swift toolchain included in *Xcode Version 11.0 or higher*.\n\nBlueSignals version 2.0 and above supports Swift 5.1+.  See older versions of BlueSSLService for older versions of Swift.\n\n### macOS\n\n* macOS 10.14.6 (*Mojave*) or higher.\n* Xcode Version 11.0 or higher using one of the above toolchains.\n* Xcode Version 12.5 or higher using the included toolchain (*Recommended*).\n\n### iOS\n\n* iOS 10.0 or higher\n* Xcode Version 11.0 or higher using one of the above toolchains.\n* Xcode Version 12.5 or higher using the included toolchain (*Recommended*).\n\n### Linux\n\n* Ubuntu 16.04 (or 16.10 but only tested on 16.04) and 18.04.\n* One of the Swift Open Source toolchain listed above.\n\n\n## Build\n\nTo build Signals from the command line:\n\n```\n% cd \u003cpath-to-clone\u003e\n% swift build\n```\n\n## Using Signals\n\n### Including in your project\n\n#### Swift Package Manager\n\nTo include BlueSignals into a Swift Package Manager package, add it to the `dependencies` attribute defined in your `Package.swift` file. You can select the version using the `majorVersion` and `minor` parameters. For example:\n```\n\tdependencies: [\n\t\t.Package(url: \"https://github.com/Kitura/BlueSignals.git\", majorVersion: \u003cmajorVersion\u003e, minor: \u003cminor\u003e)\n\t]\n```\n\n#### Carthage\nTo include BlueSignals in a project using Carthage, add a line to your `Cartfile` with the GitHub organization and project names and version. For example:\n```\n\tgithub \"Kitura/BlueSignals\" ~\u003e \u003cmajorVersion\u003e.\u003cminor\u003e\n```\n\n#### CocoaPods\nTo include BlueSignals in a project using CocoaPods, you just add `BlueSignals` to your `Podfile`, for example:\n```\n    platform :ios, '10.0'\n\n    target 'MyApp' do\n        use_frameworks!\n        pod 'BlueSignals'\n    end\n```\n\n### Before starting\n\nThe first thing you need to do is import the Signals framework.  This is done by the following:\n```\nimport Signals\n```\n\n### Provided APIs\n\nSignals provides four (4) class level APIs.  Three (3) are used for trapping and handling operating system signals.  The other function allows for the raising of a signal.\n\n#### Watching a signal\n\n``SignalWatch`` provides an interface that allows a trapped signal to notify multiple \"signal watchers\".  In this way, signal traps can be shared across libraries in the same application.  In most cases this can be used as a direct replacement for `trap()`.\n\nWhen a signal is added via ``SignalWatch``, it will install it's own handler on that signal via `trap()`.  As such, it is important to not use `trap()` directly when using ``SignalWatch``.  If all watchers of a signal are removed, ``SignalWatch`` will intelligently restore the handler that was installed before ``SignalWatch``.\n\n```swift\nimport Signals\n\n...\nlet server: SomeServer = ...\n\n\nSignalWatch.shared.on(signal: .int) { _ in\n \t\tserver.shutdownServer()\n}\n\nserver.run()\n\n```\n\n\n#### Trapping a signal\n- `trap(signal signal: Signal, action: SigActionHandler)` - This basic API allows you to set and specific handler for a specific signal.\n\nThe example below shows how to add a trap handler to a server in order to perform and orderly shutdown in the event that user press `^C` which sends the process a `SIGINT`.\n```swift\nimport Signals\n\n...\n\nlet server: SomeServer = ...\n\nSignals.trap(signal: .int) { signal in\n\n\tserver.shutdownServer()\n}\n\nserver.run()\n```\nAdditionally, convenience API's that build on the basic API specified above are provided that will allow for trapping multiple signals, each to a separate handler or to a single handler.\n- `trap(signals signals: [(signal: Signal, action: SigActionHandler)])` - This lets you trap multiple signals to separate handlers in a single function call.\n- `trap(signals signals: [Signal], action: SigActionHandler)` - This API lets you trap multiple signals to a common handler.\n\n#### Raising a signal\n- `raise(signal signal: Signal)` - This API is used to send an operating system signal to your application.\n\nThis example illustrates how to use Signals to raise a signal with the OS, in this case `SIGABRT`.\n```swift\nimport Signals\n\n...\n\nSignals.raise(signal: .abrt)\n```\n\n#### Ignoring a signal\n- `func ignore(signal: Signal)` - This API is used to ignore an operating system signal.\n\nThis example illustrates how to use Signals to ignore a signal with the OS, in this case `SIGPIPE`.\n```swift\nimport Signals\n\n...\n\nSignals.ignore(signal: .pipe)\n```\n\n#### Restoring a signals default handler\n- `func restore(signal: Signal)` - This API is used to restore an operating system signals default handler.\n\nThis example illustrates how to use Signals to restore a signals default handler, in this case `SIGPIPE`.\n```swift\nimport Signals\n\n...\n\nSignals.restore(signal: .pipe)\n```\n\n#### Adding a USER-DEFINED signal\n\nThis example shows how to add a user defined signal, add a trap handler for it and then raise the signal.\n```swift\nimport Signals\n\nlet mySignal = Signals.Signal.user(20)\n\nSignals.trap(signal: mySignal) { signal in\n\n\tprint(\"Received signal \\(signal)\")\n}\n\nSignals.raise(signal: mySignal)\n\n```\nThe output of the above snippet is:\n```\nReceived signal 20\n```\n\n## Community\n\nWe love to talk server-side Swift and Kitura. Join our [Slack](http://swift-at-ibm-slack.mybluemix.net/) to meet the team!\n\n## License\n\nThis library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/Kitura/BlueSignals/blob/master/LICENSE).\n","funding_links":[],"categories":["Libs","System [🔝](#readme)","Swift"],"sub_categories":["System"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKitura%2FBlueSignals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKitura%2FBlueSignals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKitura%2FBlueSignals/lists"}