godwords multithreading
This commit is contained in:
parent
22005153d0
commit
d5fdf36f77
25
bot.js
25
bot.js
@ -3,7 +3,8 @@ var fs = require("fs");
|
|||||||
var readline = require('readline');
|
var readline = require('readline');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var randomext = require('./random');
|
var randomext = require('./random');
|
||||||
var randomWords = require('better-random-words');
|
const { Worker } = require('worker_threads');
|
||||||
|
//var randomWords = require('better-random-words');
|
||||||
|
|
||||||
var config = { //edit your shit here
|
var config = { //edit your shit here
|
||||||
server: "irc.supernets.org",
|
server: "irc.supernets.org",
|
||||||
@ -156,16 +157,24 @@ async function godwords(chan, amt) {
|
|||||||
if (amt > 100000) {
|
if (amt > 100000) {
|
||||||
bot.say(chan, "no")
|
bot.say(chan, "no")
|
||||||
} else {
|
} else {
|
||||||
text = [];
|
|
||||||
if (amt === undefined) {
|
if (amt === undefined) {
|
||||||
var amt = 50
|
var amt = 50
|
||||||
}
|
}
|
||||||
for(var i=0; i < amt; i++){
|
//for(var i=0; i < amt; i++){
|
||||||
var word = randomWords({ exactly: 1 });
|
// var word = randomWords({ exactly: 1 });
|
||||||
text.push(word);
|
// text.push(word);
|
||||||
var string = text.join(" ")
|
// var string = text.join(" ")
|
||||||
}
|
//}
|
||||||
bot.say(chan, string);
|
const worker = new Worker('./wordgen.js', {
|
||||||
|
workerData: {
|
||||||
|
amt
|
||||||
|
}
|
||||||
|
});
|
||||||
|
worker.once('message', (string) => {
|
||||||
|
console.log('Received the hashedArray from the worker thread!');
|
||||||
|
bot.say(chan, string);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
wordgen.js
Normal file
18
wordgen.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
const { parentPort, workerData } = require('worker_threads');
|
||||||
|
const { amt } = workerData;
|
||||||
|
var randomWords = require('better-random-words');
|
||||||
|
|
||||||
|
var hashedArray = [];
|
||||||
|
var string = [];
|
||||||
|
var text = [];
|
||||||
|
for(var i=0; i < amt; i++){
|
||||||
|
var word = randomWords({ exactly: 1 });
|
||||||
|
text.push(word);
|
||||||
|
}
|
||||||
|
var string = text.join(" ")
|
||||||
|
hashedArray.push(string);
|
||||||
|
//console.log(string);
|
||||||
|
|
||||||
|
// send the hashedArray to the parent thread
|
||||||
|
parentPort.postMessage(hashedArray);
|
||||||
|
process.exit()
|
Loading…
Reference in New Issue
Block a user