我正在使用队列api并遇到了导致程序崩溃的错误.
首先,我从字典中获取队列,并在打印输出中返回该队列
获取的队列是[{[],[]}]
这是正常的吗?队列是否正确创建?
然后,当我尝试添加到队列或获取其长度时,我得到两个错误badargs.
TorrentDownloadQueue = dict:fetch(torrentDownloadQueue, State),
io:format("The fetched queue is ~p~n", [dict:fetch(torrentDownloadQueue, State)]),
% Add the item to the front of the queue (main torrent upload queue)
TorrentDownloadQueue2 = queue:in_r(Time, TorrentDownloadQueue),
% Get the lenght of the downloadQueue
TorrentDownloadQueueLength = queue:len(TorrentDownloadQueue2),
Run Code Online (Sandbox Code Playgroud)
当我尝试插入值10时,错误是
**终止原因==**{badarg,[{queue,in_r,[10,[{[],[]}]]},{ph_speed_calculator,handle_cast,2},{gen_server,handle_msg,5},{ proc_lib,init_p_do_apply,3}]}**异常退出:函数队列中的badarg:in_r/2称为队列:in_r(10,[{[],[]}])来自ph_speed_calculator的调用:handle_cast/2 in call from gen_server:从proc_lib调用handle_msg/5:init_p_do_apply/3 13>
这是in_r的错误,但我也得到了len调用的badargs错误.
我称之为或者初始队列不正确的方式有什么问题?我按如下方式创建队列并将其添加到字典中
TorrentDownloadQueue = queue:new(),
TorrentUploadQueue = queue:new(),
D4 = dict:store(torrentDownloadQueue, [TorrentDownloadQueue], D3),
D5 = dict:store(torrentUploadQueue, [TorrentUploadQueue], D4),
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么.
你拥有的([{[],[]}])是列表中的队列.标准队列看起来像{list(), list()}.显然,正因为如此,每次对队列的调用都会失败.
我的猜测是你要么把你的队列弄错了,要么以错误的方式提取它.