8000 Allow closing trap multiple times · Issue #18 · coder/quartz · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Allow closing trap multiple times #18
Open
@mafredri

Description

@mafredri

It would be nice to be able to close a trap multiple times so that the following use-case could be accommodated.

nowRecreateErrorTrap := mClock.Trap().Now("recreate", "errorTimes")
defer nowRecreateErrorTrap.Close()

// ...

if false {
	// Trap irrelevant in this condition, close via defer.
	return
}

// Only expect to use trap once, so close now and ignore future calls.
nowRecreateErrorTrap.MustWait(ctx).Release()
nowRecreateErrorTrap.Close()

// ...

This is especially useful if there are multiple branches of early interrupts.

Currently, this results in closing of closed channel.

panic: close of closed channel [recovered]
        panic: close of closed channel

goroutine 130 [running]:
testing.tRunner.func1.2({0x1b74880, 0x24f9ae0})
        /usr/local/go/src/testing/testing.go:1734 +0x21c
testing.tRunner.func1()
        /usr/local/go/src/testing/testing.go:1737 +0x35e
panic({0x1b74880?, 0x24f9ae0?})
        /usr/local/go/src/runtime/panic.go:792 +0x132
github.com/coder/quartz.(*Trap).Close(0xc00078f000)
        /home/coder/.local/go/pkg/mod/github.com/coder/quartz@v0.1.3/mock.go:637 +0x20e
github.com/coder/coder/v2/agent/agentcontainers_test.TestAPI.func2.1(0xc00051fdc0)
        /home/coder/coder/agent/agentcontainers/api_test.go:496 +0x1354
testing.tRunner(0xc00051fdc0, 0xc0003f7500)
        /usr/local/go/src/testing/testing.go:1792 +0xf4
created by testing.(*T).Run in goroutine 97
        /usr/local/go/src/testing/testing.go:1851 +0x413
FAIL    github.com/coder/coder/v2/agent/agentcontainers 0.025s
FAIL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0