No description
Find a file
2020-09-22 22:51:26 +01:00
.builds Add build status badge for debian with Nim devel to README 2020-09-13 19:16:25 +01:00
src Fix indentation 2020-09-22 22:51:26 +01:00
tests Initial commit 2020-09-11 08:52:15 +01:00
LICENSE Initial commit 2020-09-11 08:52:15 +01:00
once.nimble Initial commit 2020-09-11 08:52:15 +01:00
README.md Add build status badge for debian with Nim devel to README 2020-09-13 19:16:25 +01:00

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