mirror of
https://git.sr.ht/~euantorano/once.nim
synced 2026-01-14 02:51:39 +00:00
No description
| .builds | ||
| src | ||
| tests | ||
| LICENSE | ||
| once.nimble | ||
| README.md | ||
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) | |
| Debian (Nim devel) |