我正在使用队列api,并遇到错误使我的程序崩溃。Erlang队列问题
首先我取从字典它返回这个在打印输出
队列取出的队列是[{[],[]}]
这是正常的?队列是否正确创建?
然后,无论是当我尝试添加到队列或获得其长度,我得到一个错误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,[{队列,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的呼叫:ha ndle_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),
我不知道我做错了。
非常感谢。它现在看起来很清楚我做错了什么,我认为字典的价值必须在[]内。我不知道我为什么这样做。我一遍又一遍地检查了我的代码,忽略了这一点。我无法感谢你 – jarryd 2010-12-04 15:12:17