Files
bara-lang/lib/cljnim_async.nim
dimgigov 79cd9c08d8 chore: rebrand Clojure/Nim → Bara Lang across codebase
- Bulk replace Clojure/Nim → Bara Lang in src/, lib/, examples/, benchmarks/,
  experiments/, books/, LICENSE, cljnim.nimble, PLAN.md, AI_AGENT.md
- Rename book chapters: 05-clojure-nim.md → 05-bara-lang.md (en + bg)
- Update all chapter index links and anchors
- Replace project-specific 'Clojure' references with 'Bara Lang' in
  experiments/, src/ai_assist.nim, src/tui_screens.nim, src/emitter.nim,
  src/reader.nim, src/types.nim, lib/cljnim_runtime*.nim
- Keep legitimate JVM Clojure/ClojureScript/Clojure CLR references intact
2026-05-11 12:23:29 +03:00

36 lines
872 B
Nim

# Simplified core.async for Bara Lang
# Provides channels with put!/take!/close! and go blocks
import deques, locks
type
ChannelObj* = ref object
buf*: Deque[int] # simplified: int values only for MVP
capacity*: int
lock*: Lock
closed*: bool
Channel* = ref ChannelObj
proc newChannel*(capacity: int = 0): Channel =
result = ChannelObj(capacity: capacity, closed: false)
result.buf = initDeque[int]()
initLock(result.lock)
proc put*(ch: Channel, val: int): bool =
withLock ch.lock:
if ch.closed: return false
if ch.capacity > 0 and ch.buf.len >= ch.capacity:
return false
ch.buf.addLast(val)
return true
proc take*(ch: Channel): (bool, int) =
withLock ch.lock:
if ch.buf.len == 0:
return (false, 0)
return (true, ch.buf.popFirst())
proc close*(ch: Channel) =
withLock ch.lock:
ch.closed = true