once

Once provides a type that will enforce that a callback is invoked only once.

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version Unknown
License BSD3
CI Status Failing
Downloads 0
Last Indexed 2026-07-22 05:28

Installation

nimble install once
choosenim install once
git clone https://git.sr.ht/~euantorano/once.nim

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
once - - - - - - -

Source

Repository https://git.sr.ht/~euantorano/once.nim
Homepage https://git.sr.ht/~euantorano/once.nim
Registry Source nimble_official

README

once

Once is a Nim library that provides a type that will enforce that a callback is invoked only once.

Installation

once can be installed using Nimble:

nimble install once

Or add the following to your .nimble file:

# Dependencies

requires "once >= 1.0.0"

Usage

The tests directory has a couple of simple examples, but usage is briefly as follows:

import once

var i = 0

proc cb() =
  i += 1

var onceInstance = initOnce(cb)

for i in 0..5:
  onceInstance.run()

assert(i == 1)

Once also works in multi-threaded mode:

import once

var i = 0

proc cb() =
  i += 1

var
  onceInstance = initOnce(cb)
  thr: array[0..4, Thread[void]]

proc threadProc() {.thread.} =
  onceInstance.run()

for i in 0..high(thr):
  createThread(thr[i], threadProc)

joinThreads(thr)

assert(i == 1)

CI Status

OS Status
Debian (Nim stable) builds.sr.ht status
Debian (Nim devel) builds.sr.ht status