This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
login.use(getLoginStrategies(function (db, session, done) { | |
var retrievedUsername; | |
var setUserName = function (a) { | |
retrievedUsername = a | |
} | |
var retrievedProfile; | |
var setProfile = function (a) { | |
retrievedProfile = a | |
} | |
var user = db.getUser( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (var i = 0; i<numberOfThreads; i++) { | |
promises.push(new Promise(...)) | |
} | |
Promise.all(promises) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.any(promises) // handle the first fullfilment | |
Promise.race(promises) // handle the first settled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pool = [0,1,2,3] // 4 threads available | |
while (pool.length && queue.length) { | |
var id = pool.pop(); | |
promises.push(new Promise((...) => { | |
... | |
worker.on("exit", (...) => { | |
pool.push(id) | |
resolve() | |
}) | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (...) { | |
var id = pool.pop(); | |
promises.push(new Promise((...) => { | |
... | |
const halt = (reason) => { | |
pool.push(id) | |
reject(reason) | |
} | |
... | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (...) { | |
promises.push(new Promise((...) => { | |
... | |
const halt = (reason) => { | |
fatalPromises.push(new Promise((...) => { | |
Promise.allSettled(workers.map(w => w.terminate())) | |
.then(() => { | |
resolve2(reason) | |
}) | |
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Pool = require("jpool") | |
const path = require("path") | |
var jobs = 30; | |
const pool = new Pool({threads: 8}) | |
for (var i = 0; i < jobs; i++) { | |
pool.add(path.resolve(__dirname, 'jobs/findRandomNumber.js')) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {parentPort, workerData} = require("worker_threads"); | |
var start = new Date(); | |
const interval = setInterval(() => { | |
var number = Math.random() | |
var end = new Date(); | |
var diff = (end - start) / 1000 | |
var secs = Math.floor(diff * 100) / 100 | |
if (number > 0.9) { | |
parentPort.postMessage(`found ${number} after ${secs} seconds`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const app = express() | |
const Pool = require('jpool'); | |
// middleare | |
app.use((req, res) => { | |
const pool = new Pool(); | |
req.job = (filename) => { | |
pool.add(path.resolve(__dirname, `jobs/${filename}.js`), req) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="divide-y border"> | |
<li class="p-3">a</li> | |
<li class="p-3">b</li> | |
<li class="p-3">c</li> | |
<li class="p-3">d</li> | |
</ul> |
OlderNewer