forked from liamcottle/rustplus.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_async_requests.js
35 lines (25 loc) · 959 Bytes
/
6_async_requests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const RustPlus = require('@liamcottle/rustplus.js');
var rustplus = new RustPlus('ip', 'port', 'playerId', 'playerToken');
// wait until connected before sending commands
rustplus.on('connected', () => {
/**
* sendRequestAsync will return a promise for your request.
* you can optionally pass in a second parameter for the timeout in milliseconds
* - AppResponse packets will be sent to `then` on success.
* - AppError packets and Timeout Errors will be sent to `catch`.
*/
rustplus.sendRequestAsync({
getInfo: {}, // get server info with a timeout of 2 seconds
}, 2000).then((response) => {
// AppResponse
console.log(response);
}).catch((error) => {
// AppError or Error('Timeout');
console.log(error);
}).finally(() => {
// disconnect so our script is finished
rustplus.disconnect();
});
});
// connect to rust server
rustplus.connect();