<?php if ($device == 'mobile' || $device == 'tablet') { ?>
<script> var IS_MOBILE = true; </script><?php } ?>
if (!IS_MOBILE || $(this).valid()) {
....
}
....
if(IS_MOBILE) $('form').validate();
let frag = document.createDocumentFragment();
for(let x = 0; x < 1000; x++) {
let d = document.createElement("div");
d.innerHTML = `<h4>item ${x}</h4>`;
let svg = document.createElement("img");
svg.width = 256;
svg.height = 256;
svg.src = 'https://s3-us-west-2.amazonaws.com/svgporn.com/logos/expo.svg'
d.appendChild(svg);
frag.appendChild(d);
}
document.body.appendChild(frag);
Each message is processed completely before any other message is processed. This offers some nice properties when reasoning about your program, including the fact that whenever a function runs, it cannot be pre-empted and will run entirely before any other code runs (and can modify data the function manipulates). This differs from C, for instance, where if a function runs in a thread, it can be stopped at any point to run some other code in another thread.
'use strict';
const assert = require('assert');
const fs = require('fs');
test();
function test() {
const a = fs.createWriteStream('a.txt');
for (let i = 0; i < 5; ++i)
a.write('line\n', (e) => console.log('Write, e: ', e));
a.close();
a.on('open', () => a.close());
a.on('error', console.error);
}
return function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(req, res) {
var result;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return action(req, res);
case 3:
result = _context.sent;
return _context.abrupt('return', result);
case 7:
_context.prev = 7;
_context.t0 = _context['catch'](0);
console.error('API error', _context.t0);
return _context.abrupt('return', res.status(500).json({
message: _context.t0.message || 'Server error',
code: _context.t0.code,
stack: _context.t0.stack
}));
case 11:
case 'end':
return _context.stop();
}
}
}, _callee, _this, [[0, 7]]);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
let res1 = null, res2= null;
try {
res1 = await action1();
res2 = await action2(res1);
} catch (e) {
if(e instanceof AsyncCancellationError) {
if (res1 !== null) {
console.log('action1 executed');
// но action2 то все равно надо где-то вызвать!!!
// вариант 1:
queue.push(async () => { await action2(res1) })
// вариант 2:
await new Promise(resolve => setTimeout(resolve, 500));
res2 = await action2(res1); // callback-hell от которого как-раз и пытались избавиться
}
if (res2 !== null) console.log('action2 executed');
}
}