Comparison

util/pubsub.lua @ 8316:8648cb171213

util.pubsub: Return item-not-found if a single item is requested, and not there
author Kim Alvefur <zash@zash.se>
date Tue, 10 Oct 2017 01:41:47 +0200
parent 8312:6fd36e73082b
child 8326:12408867bc86
comparison
equal deleted inserted replaced
8315:967f04fe7fd4 8316:8648cb171213
336 local node_obj = self.nodes[node]; 336 local node_obj = self.nodes[node];
337 if not node_obj then 337 if not node_obj then
338 return false, "item-not-found"; 338 return false, "item-not-found";
339 end 339 end
340 if id then -- Restrict results to a single specific item 340 if id then -- Restrict results to a single specific item
341 return true, { id, [id] = self.data[node]:get(id) }; 341 local with_id = self.data[node]:get(id);
342 if not with_id then
343 return false, "item-not-found";
344 end
345 return true, { id, [id] = with_id };
342 else 346 else
343 local data = {} 347 local data = {}
344 for key, value in self.data[node]:items() do 348 for key, value in self.data[node]:items() do
345 data[#data+1] = key; 349 data[#data+1] = key;
346 data[key] = value; 350 data[key] = value;