Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'is-online' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
export async function prechecks() {
/* We can't work offline. */
isOnline().then(isOn => {
if (!isOn) {
throw new CodedError(
ERRORS.NETWORK_OFFLINE,
'An internet connection is required to find and render Icons.',
true
);
}
});
/* We don't want to end up deleted work-in-progress. */
const [
{ stdout: trackedFiles },
{ stdout: untrackedFiles },
] = await Promise.all([
// Checks for uncommitted changes.
execa('git', ['diff-index', 'HEAD', './']),
function checkInternetConnection() {
debug.log('Checking internet connection')
// Don't run more than one check concurrently
if (checkingInternet) {
return
}
else {
checkingInternet = true
}
// Are we online?
isOnline(function(err, internetOnline) {
if (internetOnline) {
// Is pushover reachable
isReachable('api.pushover.net:443', function(error, reachable) {
if (reachable) {
debug.log('We are online again')
clearInterval(checkInternetInterval)
online()
}
checkingInternet = false
})
}
else {
checkingInternet = false
}
})
}
return new Promise(function (resolve, reject) {
isOnline().then(online => {
if (!online) {
console.log('Не удалось скачать тему. Отсутствует соединение с интернетом!');
resolve();
return;
}
createDir(options, paths, action).then(() => {
updateteAssets(conf, state).then(() => {
getAssets(conf, action).then(function() {
if (options.theme.startBackup && options.theme.backup === 'zip') {
eventEmitter.emit('theme:zip:start', {
message: `start zip`
});
zippedDir(paths, options.pathBackup, `${options.handle}-backup`, 'backup').then(function(data){
constructor(rssFeed) {
super(rssFeed);
this.rssFeed = rssFeed;
isOnline().then(online => {
if (online === false) {
this.emit('offline', online);
} else {
this.reqFeed();
}
});
}
export async function populateQueue({concurrency = 1, tasks = [], dispatch = () => {}, options = {skipInstall: false}} = {}) {
const {skipInstall} = options;
const isNotOffline = skipInstall || await isOnline();
const customOptions = assign({}, tasks.filter(complement(isValidTask)).reduce((acc, val) => assign(acc, val), options), {isNotOffline});
const queue = new Queue({concurrency});
dispatch({type: 'status', payload: {online: isNotOffline}});
for (const [index, item] of tasks.filter(isValidTask).filter(isUniqueTask).entries()) {
const {condition, task} = item;
try {
if (await condition(customOptions)) {
await queue
.add(() => task(customOptions))
.then(() => dispatch({type: 'complete', payload: index}))
.catch(() => dispatch({
type: 'error', payload: {
index,
title: 'Failed to add task to queue',
location: 'task',
details: item.text
async _setNextOnlineState() {
var nextIsOnline = await isOnline()
if(!nextIsOnline) {
nextIsOnline = await isOnline({version: 'v6'})
}
if (this._isOnline !== nextIsOnline) {
this._isOnline = nextIsOnline
this.trigger()
}
}
async setup() {
const [
graphics,
os,
cpu,
mem,
online,
] = await Promise.all([
si.graphics(),
si.osInfo(),
si.cpu(),
si.mem(),
isOnline(),
])
this._graphics = graphics
this.os = os
this.cpu = cpu
this.memory = mem
this.online = online
logger.info(`GPU devices: ${this.graphics.length}`)
logger.info(`RAM: ${this.memory.total} bytes.`)
logger.info(`Internet connection: ${this.online}`)
logger.debug(this)
}
async preflightCheck () {
this.log.info('doing preflight checks...')
/**
* make sure connection to TV was established
* only log warning as we don't require a connection when using a launcher
*/
if (!this.tvIPAddress) {
this.log.error('Couldn\'t find a connection to TV. Please check network settings.')
}
/**
* check internet connectivity
*/
if (!await isOnline()) {
throw new Error('Couldn\'t connect to the internet')
}
/**
* check if devtools was build
*/
if (!fs.existsSync(DEVTOOLS_PATH)) {
throw new Error('Devtools frontend not found. Run `npm run build` to compile.')
}
this.log.info('preflight checks fine, no severe issues')
}
async _setNextOnlineState() {
var nextIsOnline = await isOnline()
if(!nextIsOnline) {
nextIsOnline = await isOnline({version: 'v6'})
}
if (this._isOnline !== nextIsOnline) {
this._isOnline = nextIsOnline
this.trigger()
}
}