package main
import (
"fmt"
php "github.com/kovetskiy/go-php-serialize"
)
func main() {
s := `a:6:{s:7:"__flash";a:1:{s:3:"mes";s:5:"Hello";}s:4:"__id";s:36:"3c5035d9-aea1-4f08-8325-9e598921e2a9";}`
val, err := php.Decode(s)
if err != nil {
fmt.Println(err)
return
}
session := val.(map[interface {}]interface {})
flash := session["__flash"].(map[interface {}]interface{})
fmt.Println("id", session["__id"])
fmt.Println("mes", flash["mes"])
}
session, ok := val.(map[interface {}]interface {})
if !ok {
// с val явно что-то не так, оно не соответствует типу map[interface {}]interface {}
}
flash, ok := session["__flash"].(map[interface {}]interface{})
if !ok {
// ...
}
// юзер вводит адрес http://qna.habr.com/
// браузер ресолвит это имя в IP адрес и подключается к нему по порту 80
// браузер шлёт запрос:
GET / HTTP/1.1
Host: qna.habr.com
Accept-Language: ru
// сервер, видя такое дело, соображает, что речь про сайт qna
// и что надо отдать корневую страницу
// отдаёт контент QnA
freelance.habr.com
выглядел бы похоже:// юзер вводит адрес http://freelance.habr.com/
// браузер ресолвит это имя в (тот же) IP адрес и подключается к нему по порту 80
// браузер шлёт запрос:
GET / HTTP/1.1
Host: freelance.habr.com
Accept-Language: ru
// сервер понимает, что речь про сайт freelance
let a = 'true';
if (typeof(a) === 'string'
|| typeof(a) === 'boolean'
|| typeof(a) === 'number'
){
console.log(typeof(a));
} else {
console.log('Тип а не определен');
}
let a = 'true';
if ( ['string', 'boolean', 'number'].includes(typeof(a)) ){
console.log(typeof(a));
} else {
console.log('Тип а не определен');
}
let a = 'true';
if (typeof(a) === 'string'){
console.log(a + ' - строка');
} else if (typeof(a) === 'boolean') {
console.log(a + ' - логический тип');
} else if (typeof(a) === 'number') {
console.log(a + ' - число');
} else {
console.log('Тип а не определен');
}
let a = 'true';
switch (typeof(a)) {
case 'string':
console.log(a + ' - строка');
break;
case 'boolean':
console.log(a + ' - логический тип');
break;
case 'number':
console.log(a + ' - число');
break;
default:
console.log('Тип а не определен');
}
php app.php
и процессы висят, работают. <?php
function run($timerid, $params) {
var_dump($timerid);
var_dump($params);
}
// Каждые 10 секунд выполнять функцию run
Swoole\Timer::tick(10000, "run", ["param1", "param2"]);
// Enable the hook for MySQL: PDO/MySQLi
Co::set(['hook_flags' => SWOOLE_HOOK_TCP]);
// Setup a coroutine context
Co\run(function() {
// Execute a query inside a coroutine
go(function () {
// Already setup the $pdo connection before...
$statement = $pdo->prepare("SELECT * FROM users LIMIT :limit, :offset");
$statement->execute(['limit' => $limit, 'offset' => $offset]);
$data = $statement->fetchAll();
// Process $data result...
});
});
class C {
a = 1;
f = () => this.a;
}
const x = new C();
Читал про деструктивное присвоение, но там были значения в массиве, а тут в объекте.https://developer.mozilla.org/en-US/docs/Web/JavaS...
Вроде логично, что мы сразу должны получить массив данных, а уже после с ним что-то делать, а тут мы его просто получаем и все.https://medium.com/byte-sized-react/component-arra...
const getFn = async () => {
let loading = true;
try {
// Некий проммис
} catch (e) {
// Обработка ошибки
} finaly {
loading = false;
}
}
Cooperative multitasking means: unless a running fiber deliberately yields control, it is not preempted by some other fiber. But a running fiber will deliberately yield when it encounters a “yield point”: a transaction commit, an operating system call, or an explicit “yield” request.
Transactions in Tarantool occur in fibers on a single thread. That is why Tarantool has a guarantee of execution atomicity.
И чем атомарнее хранимки, тем быстрее все работает