const promise = axios.get('https://jsonplaceholder.typicode.com/todos/1')
promise
.then(response => ({ response, items: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }))
.then(nextThen)
.catch(console.log)
const nextThen = ({ response, items }) => {
if (!items.length) {
console.log(response)
return
}
const [nextValue, ...rest] = items
promise
.then(item => axios.get(`https://jsonplaceholder.typicode.com/users/${item}`))
.then(res => {
fs.writeFileSync('test.json', JSON.stringify(res.data.phone, null, 2))
return ( { response, items: rest })
})
.then(nextThen)
return nextValue
}
channel.overwritePermissions(muterole.permissions,
http.get()
в вашем случае это и есть промис. http.get().then(a => http.get().then(b => {
// Здесь дальнейший код
}))
const p = (resolve, reject) => {
setTimeout(() => resolve(new Date()), 2000)
}
const syncFn = () => {
new Promise(p).then(console.log)
new Promise(p).then(console.log)
}
const asyncFn = async () => {
const a = await new Promise(p).then(console.log)
const b = await new Promise(p).then(console.log)
}
syncFn()
// Tue Jul 14 2020 15:17:19
// Tue Jul 14 2020 15:17:19
asyncFn()
// Tue Jul 14 2020 15:17:49
// Tue Jul 14 2020 15:17:51
function subscribe (ind = 0) {
request.post({
url: 'https://example.com',
form: {list: mis[ind]}
}, (err, response, body) => {
console.log(response.statusCode)
if (response.statusCode == 200)
subscribe (ind + 1)
})
}
subscribe()
const os = require('os'),
path = require('path'),
fs = require('fs'),
kb = require('../modules/keyboards.js'),
config = require('../config.js');
module.exports = { os, path, fs, kb, config }