gsync

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 2 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gsync 包

简介

gsync 包提供了并发同步工具。

功能特性

  • WaitGroup 增强:带超时的 WaitGroup
  • Once 增强:可重置的 Once
  • 锁工具:便捷的锁操作
  • 并发控制:并发数量控制

安装

go get github.com/snail007/gmc/util/sync

快速开始

package main

import (
    "fmt"
    "time"
    "github.com/snail007/gmc/util/sync"
)

func main() {
    // 带超时的 WaitGroup
    wg := gsync.NewWaitGroupTimeout(5 * time.Second)
    
    for i := 0; i < 3; i++ {
        wg.Add(1)
        go func(n int) {
            defer wg.Done()
            time.Sleep(time.Second)
            fmt.Println("Task", n, "done")
        }(i)
    }
    
    if wg.Wait() {
        fmt.Println("All tasks completed")
    } else {
        fmt.Println("Timeout")
    }
}

相关链接

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitGroupToChan

func WaitGroupToChan(g *sync.WaitGroup) <-chan bool

Types

type Mutex

type Mutex struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

func GetLock

func GetLock(key string) *Mutex

func (*Mutex) Unlock

func (r *Mutex) Unlock()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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