console.log(users.map(user => user.toJSON()))
const controllerCheckInput = value =>
users.find({ login: value }).then(res => !!res);
// вариант async/await
(async () => {
const exists = await controllerCheckInput('login');
console.log(exists);
})();
// then/catch
(() => {
controllerCheckInput('login').then(exists => {
console.log(exists);
});
})();
// примерно так это выглядит в express
app.post('/register', async (req, res) => {
const exists = await controllerCheckInput('login');
console.log(exists);
});
const io = socket();
io.use(async (socket, next) => {
try {
const { token } = socket.handshake.query;
const data = await verify(token);
socket.request.user = data;
return next();
} catch (err) {
// ignore
return next();
}
})
function parser() {
// request get
return Promise.delay(500).then(() => ({ results: [] }));
}
function* sequence() {
while (true) {
yield parser();
// other throwns
}
}
(async () => {
for (let parserPromise of sequence()) {
const parserResults = await parserPromise;
await Promise.delay(30 * 60 * 1000);
}
})();
import net from 'net';
const Sock = new net.Socket();
Sock.connect(PORT, HOST, () => {
console.log('connected');
})
Sock.on("data", (data) => {
console.log("receive packets: ", data);
});
import io from 'socket.io-client';
const socket = io("https://toster.ru/q/484069");