Skip to content

Instantly share code, notes, and snippets.

@Kemonozume
Last active April 23, 2017 20:11
Show Gist options
  • Save Kemonozume/ec97368db35661fe777db24c377cba18 to your computer and use it in GitHub Desktop.
Save Kemonozume/ec97368db35661fe777db24c377cba18 to your computer and use it in GitHub Desktop.
Generics nim
import asyncdispatch, times, os
type
TickerFunc* = proc (s: Ticker) : Future[void]
TickerObj[T] = object
poll: int
running*: bool
f: TickerFunc
data: T
Ticker*[T] = ref TickerObj[T]
#timer.nim(12, 3) Error: cannot instantiate: 'Ticker'
proc newTimer*[T](f: TickerFunc, data: T = nil, poll: int = 2000,) : Ticker[T] =
#Ticker[T](poll: poll, running: false, f: f, data: data)
new(result)
result.data = data
result.f = f
result.poll = poll
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment