Skip to content

Instantly share code, notes, and snippets.

View pxbuffer's full-sized avatar
🏠
Working from home

pxbuffer

🏠
Working from home
View GitHub Profile

Computation priority

For sure you've been noticed that function must be pure... or watch there is a place for side effect. Yes and we will tell about this in that section - Computation priority

A real example of queue priority - people awaiting medical treatment hospital, extreme emergency cases will have the highest priority and move on the start of the queue less significant at the end.

The main of the reason for creating Computation priority was that side effects:

  • Letting go first pure functions
  • Following consistent state of application
@pxbuffer
pxbuffer / file1.txt
Created July 10, 2019 14:50
updated gist via ajax
updated String file contents via ajax
@pxbuffer
pxbuffer / file1.txt
Created July 10, 2019 14:50
updated gist via ajax
updated String file contents via ajax
// example 1
const p1 = new Promise(resolve => setTimeout(resolve, 300, 'first promise'))
const p2 = new Promise(resolve => setTimeout(resolve, 200, 'second promise'))
const p3 = new Promise(resolve => setTimeout(resolve, 700, 'third promise'))
const p4 = new Promise(resolve => setTimeout(resolve, 500, 'fourth promise'))
const p5 = new Promise(resolve => setTimeout(resolve, 900, 'fifth promise'))
function concurrentCall(arrQueries, limit) {
const sortRes = []
// index.js
const render = () =>
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</Provider>,
root
)
const p1 = new Promise(resolve => setTimeout(resolve, 300, 'first promise'))
const p2 = new Promise(resolve => setTimeout(resolve, 200, 'second promise'))
const p3 = new Promise(resolve => setTimeout(resolve, 700, 'third promise'))
const p4 = new Promise(resolve => setTimeout(resolve, 500, 'fourth promise'))
const p5 = new Promise(resolve => setTimeout(resolve, 900, 'fifth promise'))
function concurrentCall(arrQueries, count) {
const sortRes = []
return new Promise(resolve => {
var weatherForecast = {
id: '',
country: '',
temperature: ''
}
var xhr = new XMLHttpRequest();
function query(url) {
xhr.open('GET', url);
async function updateUser(token) {
let cancelled = false;
// we don't reject, since we don't have access to
// the returned promise
// so we just don't call other functions, and reject
// in the end
token.cancel = () => {
cancelled = true;
};
function CoffeeMachine(power, capacity) {
Machine.apply(this, arguments);
let waterAmount;
const WATER_HEAT_CAPACITY = 4200;
let timerId;
console.log('Create coffee machine with capacity of ' + power + ' vt');
this.setWaterAmount = function (amount) {
if (amount < 0) throw new Error('The number must be positive');
if (amount > capacity) throw new Error('Do not add more water then ' + capacity);
<?
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php");
$APPLICATION->SetTitle("1С-Битрикс: Управление сайтом");
CModule::IncludeModule('iblock');
$arrConcert = array();
$res3 = CIBlockElement::GetList(array('PROPERTY_DATE' => 'ASC'),array( 'IBLOCK_ID' => 1,));
while ($obj = $res3->GetNextElement()){