Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

ringabout/channel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

channel

Upcoming Nim channel implementation for ORC(the development is moved to nim-lang/Nim#17305)

a motivate example

import channel
import std/[httpclient, isolation, json]


var ch = initChan[JsonNode](kind = Spsc)


proc download(client: HttpClient, url: string) =
  let response = client.get(url)
  echo "content: "
  echo response.body[0 .. 20]

proc worker =
  var client = newHttpClient()
  var data: JsonNode
  ch.recv(data)
  if data != nil:
    for url in data["url"]:
      download(client, url.getStr)
  client.close()

proc prepareTasks(fileWithUrls: string): seq[Isolated[JsonNode]] =
  result = @[]
  for line in lines(fileWithUrls):
    result.add isolate(parseJson(line))

proc spawnCrawlers =
  var tasks = prepareTasks("todo_urls.txt")
  for t in mitems tasks:
    ch.send move t # or ch.send t.extract

var thr: Thread[void]
createThread(thr, worker)

spawnCrawlers()
joinThread(thr)

Useful materials

nim-lang/RFCs#244

About

Upcoming Nim channel implementation for ORC

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages