Closed frct1 closed 6 years ago
Normally you would use the break
keyword to jump out of a for
- or while
-loop, but it won't work in this case. The error-callback will, due to JavaScripts asynchronous nature, most certainly only get called once the for
-loop is long done.
Note: I don't have time right now, I will extend this comment later :)
Also: Look at the documentation for the serverlist
command. I think it does what you actually want.
No, this command does not help, because we need to do sorting (there may be problems with async).
The most useful option is to make use
and in case of an error create a server and break
the loop.
What exactly are you trying to achieve?
So, whe have a port range for instance (from 10020 to 10050 for example) for one ts3 instance. When we need to create server on this instance => we must get unused port for server only from this range (it is need if we are using same ip for different instances, using different sq port). Lately i'm created it in php with function
public function findPort($startp, $endp)
{
try{
for ($tport = $startp; $tport <= $endp; ++$tport) {
if (!$this->serverGetByPort($tport)) {
return $tport;
}
}
}
catch (TeamSpeak3_Exception $e) {
return $tport;
}
}
In php we can return unused tport
(iterator) easy. But in nodejs have troubles with this.
So you essentially want to have every port from 10020 – 10050 occupied by a virtual server?
The error (UnhandledPromiseRejectionWarning
, see this stackoverflow answer) you are getting is probably happening, because your createServer
function uses Promises (Presumably calling query.send
) and doesn't provide a catch
handler. The try-catch can't work, because that is for handling synchronous errors.
If you want to learn more about Promises: I found this guide to be quite good in explaining the basic properties and use cases of them.
Edit: Added link to stackoverflow answer.
Any updates? Can I close the issue?
Hi, currently learning the art of promises :) Yes, we can close this thread. Thanks for the docs.
Interesting topic. Good luck and have fun ;)
Hi, it`s me again. Have a question: how get free port by the loop (for) with ports range and if we get free port then do server install. Code for example
I am haven't any ideas how realize this.
Edit (schroffl): Code Formatting