1

次のNimプログラムがあります:

import threadpool

var channel: TChannel[string]

proc consumer(channel: TChannel[string]) =
  let (flag,msg) = tryRecv(channel)
  if flag:
    echo msg

channel.open()
spawn consumer(channel)
channel.send("hello")
channel.close()
sync()

コンパイルしようとすると、次のエラー メッセージが表示されます。

testchannels.nim(6, 27) Error: type mismatch: got (TChannel[system.string])
but expected one of: 
system.tryRecv(c: var TChannel[tryRecv.TMsg])

エラーメッセージが何を伝えようとしているのか理解できません...

4

1 に答える 1

1

ああ、私は今それを手に入れたと思います!

エラー メッセージの重要な部分は次varsystem.tryRecv(c: var TChannel[tryRecv.TMsg])とおりです。

解決策は、consume proc からパラメーターを削除することです。

import threadpool

var channel: TChannel[string]

proc consumer() {.gcsafe.} =

  if peek[string](channel) != -1:
    echo recv(channel)

channel.open()
spawn consumer()
channel.send("hello")
channel.close()
sync()
于 2015-07-03T15:19:57.837 に答える