From a66958c9d3de36f7f6d704211005104f14530013 Mon Sep 17 00:00:00 2001 From: E_L <54755533+ELchem@users.noreply.github.com> Date: Sat, 1 Jul 2023 00:55:34 -0400 Subject: [PATCH 1/2] feat: add a new API `ReleaseTimeout` for the default pool (#285) Co-authored-by: EL --- ants.go | 5 +++++ ants_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ants.go b/ants.go index 18b3dc8..4ec81fa 100644 --- a/ants.go +++ b/ants.go @@ -123,6 +123,11 @@ func Release() { defaultAntsPool.Release() } +// ReleaseTimeout is like Release but with a timeout, it waits all workers to exit before timing out. +func ReleaseTimeout(timeout time.Duration) error { + return defaultAntsPool.ReleaseTimeout(timeout) +} + // Reboot reboots the default pool. func Reboot() { defaultAntsPool.Reboot() diff --git a/ants_test.go b/ants_test.go index 93bbbea..c216066 100644 --- a/ants_test.go +++ b/ants_test.go @@ -973,3 +973,15 @@ func TestReleaseTimeout(t *testing.T) { err = pf.ReleaseTimeout(2 * time.Second) assert.NoError(t, err) } + +func TestDefaultPoolReleaseTimeout(t *testing.T) { + Reboot() + for i := 0; i < 5; i++ { + _ = Submit(func() { + time.Sleep(time.Second) + }) + } + assert.NotZero(t, Running()) + err := ReleaseTimeout(2 * time.Second) + assert.NoError(t, err) +} From 45a0390a9f6c679714c03ba4fb7374bcf7304ec3 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 1 Jul 2023 14:37:05 +0800 Subject: [PATCH 2/2] chore: refine paths-ignore for all GitHub actions --- .github/workflows/codeql.yml | 16 ++++++---------- .github/workflows/test.yml | 18 ++++++------------ 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ad47ade..56a7542 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -7,22 +7,18 @@ on: - dev paths-ignore: - '**.md' - - '.github/FUNDING.yml' - - '.github/release-drafter.yml' - - '.github/ISSUE_TEMPLATE/*' - - '.github/workflows/pull-request.yml' - - '.github/workflows/release-drafter.yml' + - '**.yml' + - '**.yaml' + - '!.github/workflows/codeql.yml' pull_request: branches: - master - dev paths-ignore: - '**.md' - - '.github/FUNDING.yml' - - '.github/release-drafter.yml' - - '.github/ISSUE_TEMPLATE/*' - - '.github/workflows/pull-request.yml' - - '.github/workflows/release-drafter.yml' + - '**.yml' + - '**.yaml' + - '!.github/workflows/codeql.yml' schedule: # ┌───────────── minute (0 - 59) # │ ┌───────────── hour (0 - 23) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f595e42..d0481a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,26 +7,20 @@ on: - dev paths-ignore: - '**.md' - - '.github/FUNDING.yml' - - '.github/release-drafter.yml' - - '.github/ISSUE_TEMPLATE/*' - - '.github/workflows/codeql.yml' - - '.github/workflows/pull-request.yml' - - '.github/workflows/release-drafter.yml' + - '**.yml' + - '**.yaml' - 'examples/*' + - '!.github/workflows/test.yml' pull_request: branches: - master - dev paths-ignore: - '**.md' - - '.github/FUNDING.yml' - - '.github/release-drafter.yml' - - '.github/ISSUE_TEMPLATE/*' - - '.github/workflows/codeql.yml' - - '.github/workflows/pull-request.yml' - - '.github/workflows/release-drafter.yml' + - '**.yml' + - '**.yaml' - 'examples/*' + - '!.github/workflows/test.yml' env: GO111MODULE: on