You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (isMainThread) {
/* The acceptorApp only listens, but must be SSL if worker apps are SSL and likewise opposite */
const acceptorApp = uWS.SSLApp({
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).listen(port, (token) => {
if (token) {
console.log('Listening to port ' + port + ' from thread ' + threadId + ' as main acceptor');
} else {
console.log('Failed to listen to port ' + port + ' from thread ' + threadId);
}
});
/* Main thread loops over all CPUs */
/* In this case we only spawn two (hardcoded) */
/*os.cpus()*/[0, 1].forEach(() => {
/* Spawn a new thread running this source file */
new Worker(__filename).on("message", (workerAppDescriptor) => {
acceptorApp.addChildAppDescriptor(workerAppDescriptor);
});
});
/* I guess main thread joins by default? */
} else {
/* Here we are inside a worker thread */
const app = uWS.SSLApp({
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).get('/*', (res, req) => {
res.end('Hello Worker!');
}).listen(4000, (token) => {
if (token) {
console.log('Listening to port ' + 4000 + ' from thread ' + threadId);
} else {
console.log('Failed to listen to port ' + 4000 + ' from thread ' + threadId);
}
});
/* The worker sends back its descriptor to the main acceptor */
parentPort.postMessage(app.getDescriptor());
}
Testing on ubuntu 24.04
The text was updated successfully, but these errors were encountered:
I was also not able to get the worker thread example working. I used the following script:
importuWSfrom'uWebSockets.js'import{Worker,isMainThread,threadId,parentPort}from'node:worker_threads'constport=9001const__filename=newURL(import.meta.url).pathnameif(isMainThread){constacceptorApp=uWS.App()acceptorApp.listen(port,(token)=>{if(token){console.log('Listening to port '+port+' from thread '+threadId+' as main acceptor')}else{console.log('Failed to listen to port '+port+' from thread '+threadId)}})constthreads=[0,1]threads.forEach(()=>{/* Spawn a new thread running this source file */newWorker(__filename).on('message',(workerAppDescriptor)=>{acceptorApp.addChildAppDescriptor(workerAppDescriptor)})})/* I guess main thread joins by default? */}else{/* Here we are inside a worker thread */constapp=uWS.App().get('/*',(res,req)=>{res.end('Hello Worker!')}).listen(4000,(token)=>{if(token){console.log('Listening to port '+4000+' from thread '+threadId)}else{console.log('Failed to listen to port '+4000+' from thread '+threadId)}})/* The worker sends back its descriptor to the main acceptor */parentPort?.postMessage(app.workerAppDescriptor)}
There is no function called getDescriptor nor workerAppDescriptor property. Any feedback how to achieve this?
code like this:
Testing on ubuntu 24.04
The text was updated successfully, but these errors were encountered: