![](https://steemitimages.com/DQmdRwjzRvEMqG4VUABL4z7RFnk6rrYnr75Q2UDSdW95Sk6/image.png)
Hail fellow code wizards. Writing this post today in hopes of collecting the right information / logic / computer words to fix an issue I've been having with my Tippy project currently being developed.
Basically my service is 90% coded functionality wise at this point! But one seemingly daunting problem I've had on it is developing a queue system for voting and comment replies to skirt the 3 and 20 seconds limits imposed by the STEEM blockchain.
What I'm looking for is a function using steemjs module capability that takes in the following variables, checks to see if we're currently waiting for a 20 second post limit or 3 second vote limit, enqueues the comment or vote for later if finds it's delayed and follows a FiFo (First in, First Out) style of processing what's thrown at it.
Variables that must be digested. and enqueued for sending ASAP:
- wif
- parentAuthor
- parentPermlink
- tippy (bot name variable)
- permlink
- title
- content
- metadata
- block
I'll share my current code below that I'm using.. While it "sort of" works unfortunately I've been unable to get the function to work as I'd hoped, and thus am asking the community of coders here on Steemit to have a look over what I have and offer their thoughts or methods on achieving what I've been struggling with.
function commentQueue() {
this.elements = [];
};
// enqueue a new thingy
commentQueue.prototype.enqueue = function (e) {
this.elements.push(e);
};
// remove an element from the front of the queue
commentQueue.prototype.dequeue = function () {
return this.elements.shift();
};
// check if the queue is empty
commentQueue.prototype.isEmpty = function () {
return this.elements.length == 0;
};
// get the element at the front of the queue
commentQueue.prototype.peek = function () {
return !this.isEmpty() ? this.elements[0] : undefined;
};
var qc = new commentQueue();
var cr;
var timetimetime = 1000;
function countdown() {
count = 19;
if (count >= 0){
var timerId = setInterval(function() {
console.log("║".blue + logo + " W ".blue.dim + "WAIT".grey.dim + " │ ".blue + count + "s on Post Limiter");
count--;
if(count <= 0) {
// your code goes here
clearInterval(timerId);
count = 0;
commentwait = false;
timetimetime = 1000;
}
}, timetimetime);
};
}
var counttime = parseFloat(count + "000");
// counttime = (count * 1000);
//----- Reply to comment function
var replycomment = function (wif, parentAuthor, parentPermlink, tippy, permlink, title, content, metadata, block) {
if (debugmode == true) {
console.log("║".blue + logo + " ~ DBUG".magenta.dim + " │ ".blue + "function ".magenta.dim + "replycomment".blue.bold + "(".white.dim + wif + "," + parentAuthor + "," + parentPermlink + "," + tippy + "," + permlink + "," + title + "," + content + "," + metadata + "," + block + ")".white.dim);
};
if(commentwait == false){
steem.broadcast.comment(wif, parentAuthor, parentPermlink, tippy, permlink, title, content, metadata, function (commentfailz, commentwinz) {
if (commentfailz) {
if (debugmode == true) {
console.log(commentfailz);
};
console.log("║".blue + logo + " W ".yellow.dim + "WAIT".yellow + " │ ".blue + "Waiting on Comment Limiter to F**k Off!");
setTimeout(function() {
// Load first op without removing
steem.broadcast.comment(wif, parentAuthor, parentPermlink, tippy, permlink, title, content, metadata, function (errqc, winqc) {
if(errqc){
}
if(winqc){
console.log("║".blue + logo + " > ".green.bold + "SEND".green.bold + " │ ".blue + time + "@" + parentAuthor + "'s Response Sent on Block #" + headstreamblock);
countdown();
}
});
}, counttime)
}; //END if (commentfailz)
if (commentwinz) {
console.log("║".blue + logo + " > ".green.bold + "SEND".green.bold + " │ ".blue + time + "@" + parentAuthor + "'s Response Sent on Block #" + headstreamblock);
if (debugmode == true) {
console.log(commentwinz);
};
countdown();
}
});
} else {
console.log("║".blue + logo + " W ".yellow.dim + "WAIT".yellow + " │ ".blue + "Waiting on Comment Limiter to F**k Off!");
setTimeout(function() {
// Load first op without removing
console.log("║".blue + logo + " > ".yellow.dim + "SEND".yellow.dim + " │ ".blue + "@" + parentAuthor + "'s Queued Response is Broadcasting");
steem.broadcast.comment(wif, parentAuthor, parentPermlink, tippy, permlink, title, content, metadata, function (errqc, winqc) {
if(errqc){ console.log("something fucked up") };
if(winqc){
console.log("║".blue + logo + " > ".green.bold + "SEND".green.bold + " │ ".blue + "@" + parentAuthor + "'s Response Sent on Block #" + headstreamblock);
countdown();
};
});
}, counttime)
};
};//END replycomment
If anyone can spot where I've gone wrong (besides the obvious self taught hacky as hell code) or has a nodeJS function that does what I'm looking to accomplish they don't mind sharing I'd highly appreciate it! Been scratching my noodles and trial and erroring against this problem for too damn long now. Time to get a hand, get it working and continue forwards!
Looking forward to getting Tippy running and it's source code released to the public before STEEM communities get implemented..! Will be exciting times for sure and will allow me to move onto other projects I've been neglecting over the past while. Thanks for reading and kudos in advance for any advice or debug help offered. <3
![]() | ![]() |
---|
Alright - I couldn't test it myself but I've tried my best for the last hour and a half. I've added a bit of code and tried a solution without the timeout - only with the cooldown.
https://pastebin.com/UugVXJXx
Please test it and let me know what happened :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hell yeah dude! Will plug this in and see what happens. Much appreciate the effort!
I'll shoot ya a bit of SBD now regardless. Firm believer in compensation for work. :)
Followed you as well. Anyone willing to help ole KLYE slog through his work is good in my books.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Just saw the notification - thank you klye! Very much appreciate it. But I was in the first place intrigued in solving a "code-challenge". Hehe.
I really hope it works or at least gives you some new input. :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
No worries man. Gotta help those who take time to help you.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I don't know about the function code, thanks
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I know nothing of coding,but gave it a resteem if it might help out :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you very much! Suprised no ones come in here and schooled me yet. XD
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Lol yeah I thought people will be swarming the comments...guess thay are sleeping ;)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
What is this sleeping you speak of? lol
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Trust me....you dont want to know...
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Could be wrong .. but should you set count to 19 then check value...wouldn't it be 19 since you just set it. Way too early for thinking here.. :) Good luck. Something with countdown just seems off but not at a computer. I would think when count < 0, you would break out and reset to 19 to start counter over again since you are counting down. Again could be wrong. :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Haha @fabien sent me this link saying that maybe my new SteemBot might help. Actually it doesn't have a Queue system yet for this purpose but I think having it on that would be an amazing idea!
Anyhow, I think you can accomplish this task with much less code in a simple queue system. You can use this queue in a shared manner or have one queue array for each function if you want a 20sec queue and a 3 sec queue.
Notice that I used some ES6 syntax to make it more clear. If your env doesn't support it just add babel-register on top of your code or use babel-cli to compile it. Also better not to run it in jsbin, it's not supposed to work there. Hope it helps.
http://jsbin.com/yeriqor/edit?js,console
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
ooooh! This is nice p0o! Thanks for the share.
Can I use snippets of your code? While it looks like you've done a wonderful job on this package I only need a very tiny part of its offering!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Sure the license is MIT and I mean it. However I appreciate some kind of support in the form of starring the repository and creating issues if you had any. Thanks
BTW sorry for late reply. I missed it.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
In your function countdown(), you set the count variable to 19 and just after you test if >=0, always true! You can remove the test.
But I guess that is not the solution to your problem.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit