semaphore

command module
v0.0.0-...-962c5bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2021 License: MIT Imports: 5 Imported by: 0

README

semaphore

A shell tool to create counting semaphores, acquire them and release them. This is useful if you want to e.g. run no more than N out of M commands in parallel.

usage

Create a semaphore of size 10 for a job that will fetch URLs in parallel.

semaphore create --name fetch-many-urls --size 10

Then before launching each job, acquire the semaphore:

semaphore acquire --name fetch-many-urls

Do your job, and when you're done:

semaphore release --name fetch-many-urls
example
#!/usr/bin/env bash

lockname=$(uuidgen)
semaphore create --name ${lockname} --size 2

function fetch_url() {
    local url=${1}
    semaphore acquire --name ${lockname}
    echo "fetching URL ${1}"
    sleep 1
    semaphore release --name ${lockname}
}

for ((i=0; i<=10; i++)); do
    fetch_url "http://url.number.${i}" &
done

wait $(jobs -p)

using it

Grab a release or :

on macOS

brew tap aybabtme/homebrew-tap
brew install semaphore

license

The tool here is MIT. The code is 99.9% powered by a fork of bitbucket.org/avd/go-ipc, which is Apache 2.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL