【发布时间】:2010-12-04 23:10:04
【问题描述】:
我正在使用队列 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),
当我尝试插入值 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 的调用 来自 gen_server:handle_msg/5 的调用 从 proc_lib: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),
我不知道我做错了什么。
【问题讨论】: