I am using the queue api and have encountered to errors which crash my program.
First off I fetch the queue from the dictionary which returns this in a printout
The fetched queue is [{[],[]}]
Is this normal? Is the queue created correctly?
Then either when I try add to the queue or get its length I get an error badargs on both.
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),
When I try to insert the value 10 the error is
** Reason for termination == ** {badarg,[{queue,in_r,[10,[{[],[]}]]}, {ph_speed_calculator,handle_cast,2}, {gen_server,handle_msg,5}, {proc_lib,init_p_do_apply,3}]} ** exception exit: badarg in function queue:in_r/2 called as queue:in_r(10,[{[],[]}]) in call from ph_speed_calculator:handle_cast/2 in call from gen_server:handle_msg/5 in call from proc_lib:init_p_do_apply/3 13>
This is the error for the in_r, but I get a badargs error for the len call too.
What is wrong with the way I call these or is the inital Queue incorrect? I create the queue as follows and add it to the dictionary
TorrentDownloadQueue = queue:new(),
TorrentUploadQueue = queue:new(),
D4 = dict:store(torrentDownloadQueue, [TorrentDownloadQueue], D3),
D5 = dict:store(torrentUploadQueue, [TorrentUploadQueue], D4),
I have no idea what I am doing wrong.