How to fix the error and run functions in an asynchronous thread?
D:\nim-2.0.2\lib\pure\asyncmacro.nim(160, 5) webServerMatcher (Async)
D:\pojects\MelonPlayer\source_code_app\main.nim(166, 3) template/generic instantiation of `router` from here
C:\Users\user\.nimble\pkgs2\jester-0.6.0-4834f85e61ae39f6b6acfb74d3bbba62d8779b66\jester.nim(1352, 35) template/generic instantiation of `async` from here
D:\pojects\MelonPlayer\source_code_app\main.nim(222, 13) template/generic instantiation of `await` from here
D:\nim-2.0.2\lib\pure\asyncmacro.nim(160, 5) Error: await expects Future[T], got void
Tip: 46 messages have been suppressed, use --verbose to show them.
nimble.nim(229) buildFromDir
libs: nigui, jester
code:
proc startServer() {.thread, nimcall.} =
echo "server thread started!"
router webServer:
get "/send@command?":
if @"command" != "" and @"command".len() != 0:
var arguments = findTextInBrackets(@"command")
var packet: seq[string]
for (index, text) in arguments:
let commandPart = @"command"[0..<index] # Получаем подстроку "command" до заданного индекса
let parts = commandPart.split(
".") # Разбиваем подстроку по символу '.'
# Добавляем полученные части в список packet
packet.add(parts)
echo packet
...
elif packet[0] == "send":
case packet[1]
of "error":
await echoError()
resp "Start the Error windows"
else:
resp "{:red:}" & @"command" & " not found!"
else:
resp "{:red:}" & @"command" & " not found!"
else:
resp @"command" & " not found!"
proc echoError(error: string = "error", typeError: string = "") =
var window = newWindow()
var listButtons = @["OK", "Exit", "Copy Error"]
var res: int
if typeError == "warn":
res = window.msgBox(message = "Error:\n\n" & $error,
title = "Melon Player Error:", button1 = fmt"{listButtons[0]}")
elif typeError == "error" or typeError == "fatal":
res = window.msgBox("Error:\n\n" & $error, "Melon Player Error:",
listButtons[0], listButtons[1], listButtons[2])
if res == 1:
quit()
elif res == 2:
var cb = clipboard_new(nil)
if cb.clipboard_set_text(error):
quit()
else:
echo "Copy error"
у меня получается другая ошибка: D:nim-2.0.2libpureasyncmacro.nim(250, 31) Error: 'echoError (Async)' is not GC-safe as it calls 'msgBox'
msgbox - функция с библеотеки nigui, а туда я не смогу никак добавить асинхронность.
I'm getting a different error: D:nim-2.0.2libpureasyncmacro.nim(250, 31) Error: 'echoError (Async)' is not GC-safe as it calls 'msgBox'
msgbox is a function from the nigui library, and there's no way I can add asynchrony there.
я посмотрел примеры использования nigui в их репозитории
https://github.com/simonkrauter/NiGui/blob/master/examples/example_01_basic_app.nim
похоже, тебе надо запустить сервер и оконное приложение в отдельных потоках и наладить их общение через каналы
чтобы решить эту проблему побыстрому можно на свой страх и риск сделать так:
nim
{.cast(gcsafe).}:
echoError()
но для будущего лучше запустить гуи и сервер в разных потоках и настроить между ними простую коммуникацию типо через канал передавать сообщение и ссылку на объект с доп данными если надо, а там на месте конвертировать
i saw usage examples in the nigui repository
seems you need to run server and window application in separates threads and establish their communication through channels
in your own risk you can cast your echoError to gcsafe using pragma
but for sake of future it is better to run gui and server in separate threads and set up communication between them using channel, and send messages and additional ref object if you need, and then cast that ref to any object