🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

l7e.io/yama

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

l7e.io/yama

Go Modules
Version
v0.2.0
Version published
Created
Source

yama

A signal watcher that can be used to shutdown an application.

Build Status Go Report Card Documentation Coverage Status License GitHub tag (latest SemVer)

Image of Yama

Yama provides a signal watcher that can be used to shutdown an application1.

A signal watcher can be constructed to watch any number of signals and will call any number of registered io.Closer instances, when such signals occur; the results of calling Close() on the registered instances are ignored.

watcher := yama.NewWatcher(
	yama.WatchingSignals(syscall.SIGINT, syscall.SIGTERM),
	yama.WithTimeout(2*time.Second),
	yama.WithClosers(server))

An application can wait fir the completion of the Closer notifications by calling the blocking method, Wait().

watcher.Wait()

Here, the caller will be blocked until one of the signals occur and all the Closer notifications have either completed or two seconds have elapsed since the start of Closer notifications; the timeout is set above by passing yama.WithTimeout(). Subsequent signals will not trigger Closer notifications.

The application can programmatically trigger Closer notifications by calling

watcher.Close()

If this is done, subsequent signals will not trigger Closer notifications.

There are a few helper methods, FnAsCloser() and ErrValFnAsCloser(), that can be used to wrap simple functions and functions that can return an error, respectively, into instances that implement io.Closer.

1: Inspired by Death.

FAQs

Package last updated on 05 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts