Skip to content

Instantly share code, notes, and snippets.

@dom96
Forked from anonymous/asyncgetter.nim
Last active August 29, 2015 14:06
Show Gist options
  • Save dom96/2d63e2a31a30feae54ea to your computer and use it in GitHub Desktop.
Save dom96/2d63e2a31a30feae54ea to your computer and use it in GitHub Desktop.
import asyncdispatch, httpclient, os, strutils
# ~/nimbb/nim/bin/nim c --threadAnalysis:off -d:ssl -r tcrawl3.nim 10 300 500
var numRunning = 0
var good = 0
var bad = 0
# not used....
var concurrency = 3
if paramCount() > 0:
concurrency = paramStr(1).parseInt()
var sleepTime = 300
if paramCount() > 1:
sleepTime = paramStr(2).parseInt()
var numToRun = 30
if paramCount() > 2:
numToRun = paramStr(3).parseInt()
var totGot = 0
proc createRequest(url: string) {.async.} =
numRunning += 1
echo "numRunning: ", numRunning
var client = newAsyncHttpClient()
try:
let resp = await client.request(url)
echo("Got resp: ", resp.status)
good += 1
echo "good: ", good
except:
bad += 1
echo "bad: ", bad
echo("Exception!")
numRunning -= 1
totGot += 1
echo "got: ", totGot
# 1000 domains
var domurl = "http://goo.gl/yzlQ5n"
var doms = getContent(domurl).split("\n")
echo doms
#quit()
when isMainModule:
for x in low(doms)..numToRun:
asyncCheck createRequest("http://www." & doms[x])
while numRunning > 0:
poll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment