summary refs log tree commit diff stats
path: root/tests/generics/tcan_specialise_generic.nim
blob: 78896db38f09241cb153d89445dd625f052857f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
##
## can_specialise_generic Nim Module
##
## Created by Eric Doughty-Papassideris on 2011-02-16.

type
  TGen[T] = object {.inheritable.}
  TSpef = object of TGen[string]
="nf">progress(status: DownloadStatus, progress: uint, total: uint, message: string) {.gcsafe.} = echo "Downloading " & url let t = total.BiggestInt if t != 0: echo clamp(int(progress.BiggestInt*100 div t), 0, 100), "%" else: echo "0%" downloadToFile(url, file, {optUseCache}, progress) echo "100%" else: import os, asyncdispatch, httpclient proc syncDownload(url, file: string) = var client = newHttpClient() proc onProgressChanged(total, progress, speed: BiggestInt) = echo "Downloading " & url & " " & $(speed div 1000) & "kb/s" echo clamp(int(progress*100 div total), 0, 100), "%" client.onProgressChanged = onProgressChanged client.downloadFile(url, file) echo "100%" if os.paramCount() != 2: quit "Usage: nimgrab <url> <file>" else: syncDownload(os.paramStr(1), os.paramStr(2))