-
Notifications
You must be signed in to change notification settings - Fork 8
Functions (Threads)
Running functions through threads is very similar to a regular launch through BasRemoteClient
. The main feature of this type of launch is that you can control the launch yourself, stop the thread, and check whether it is busy with the execution of functions. This is very convenient cause it gives you complete control over the execution of functions.
If you want to create new thread then use client.сreateThread()
method. This method returns object that contains several useful methods and properties. Take a look at example.
const thread = client.createThread();
// Set up proxy.
await thread.runFunction('SetProxy', {
Proxy: '127.0.0.1:11185',
IsSocks5: 'true',
});
// Check the ip of this proxy.
const proxyIp = await thread.runFunction('CheckIp');
// Stop the thread.
thread.stop();
Obviously, starting threads manually and calling functions through client is very similar. But in the case of a manual start, you can for example check if the thread is busy with function, and run the function if thread is free using isRunning
property.
// Run function only if thread is free.
if (!thread.isRunning) {
await thread.runFunction('SomeFunction');
}
// Run another function only if thread is free.
if (!thread.isRunning) {
await thread.runFunction('SomeAnotherFunction');
}