---
source: https://iinventedlight.com/library/notes/go-once.md
title: "sync.Once: run an action exactly once"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go project); CC-BY-4.0 (Go project); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go project, sync/once.go; Go project, sync package. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-once"
tags: [go, sync, once, concurrency]
client: Librarian
sources:
  - id: S1
    title: "sync/once.go"
    publisher: Go project
    url: https://go.dev/src/sync/once.go
    accessed: 2026-11-23
    license: "BSD-3-Clause"
  - id: S2
    title: "sync package"
    publisher: Go project
    url: https://pkg.go.dev/sync
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# sync.Once: run an action exactly once
**Answer:** Once is an object that will perform exactly one action. Call Do(f) to run that action. Future calls of Do return without calling f. A Once must not be copied after first use.

## The Once contract

The Once type is an object whose job is to perform one action, and only one.

After first use, copying a Once is not allowed.

Call Do(f) as many times as you want; only that first call will invoke f. Only the first call will invoke f. A new instance of Once is required for each function to execute.

## Do and initialization

Package docs repeat that Once will perform exactly one action.

Do is intended for initialization work that has to run exactly once.

Do does not return until f returns. If f causes Do to be called, it will deadlock.

## See also

- [go-atomic](https://iinventedlight.com/library/notes/go-atomic/)
- [go-context](https://iinventedlight.com/library/notes/go-context/)

## Claims

- id: C1
  claim: Once is an object that will perform exactly one action.
  source: S1
  evidence: "will perform exactly one action"

- id: C2
  claim: A Once must not be copied after first use.
  source: S1
  evidence: "must not be copied after first use"

- id: C3
  claim: Do is intended for initialization that must be run exactly once.
  source: S2
  evidence: "initialization that must be run exactly once"

- id: C4
  claim: If f causes Do to be called, it will deadlock.
  source: S2
  evidence: "if f causes Do to be called, it will deadlock"

## Sources

- [S1] sync/once.go. Go project. https://go.dev/src/sync/once.go . License: BSD-3-Clause. Accessed 2026-11-23.

- [S2] sync package. Go project. https://pkg.go.dev/sync . License: CC-BY-4.0. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go project, sync/once.go; Go project, sync package. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. CC-BY-4.0 (https://go.dev/copyright). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
