const DEVELOPER_INFO = [
" autor " => " Matheus Johann Araújo " ,
" country " => " Brasil " ,
" state " => " Pernambuco " ,
" date " => " 2022-03-12 "
]; Der Begriff callback bedeutet die Funktion der vergangenen Funktion als Parameter einer Funktion, die von einer Funktion aufgerufen wird. In PHP callable es sich bei den callbacks , was kampfbar ist.
Die Klasse, die als Closure bezeichnet wird, ist für die Darstellung anonymer Funktionen und arrow functions (Pfeilfunktionen) verantwortlich.
callback sind normalerweise unbenannte Funktionen (anonyme oder Pfeilfunktionen), die mit dem Parameter übergeben werden, aber nichts verhindert, dass eine benannte Funktion als Parameter übergeben wird!
setInterval(callback, milliseconds) führt die Rückruffunktion in unendlich informierter Zeit aus. Die Funktion gibt eine UID zurück, die in der clearInterval -Funktion verwendet werden kann, um setInterval aus der Ausführungszeile zu entfernen.
setTimeout(callback, milliseconds) führt den Callback -Funktionsaufruf in der Zeit auf einzigartige Weise aus. Die Funktion gibt eine UID zurück, die in der clearTimeout -Funktion verwendet werden kann, um die setTimeout aus der Ausführungszeile zu entfernen.
clearInterval(UID) vervollständigt die zukünftige Ausführung des setInterval , der die informierte UID hat. Die Funktion gibt true (fertig) oder false zurück (hat die geplante Aufgabe nicht beendet oder fand nicht nicht);
clearTimeout(UID) schließt die zukünftige Ausführung des setTimeout mit der informierten UID ab. Die Funktion gibt true (Fertig) oder false zurück (die geplante Aufgabe nicht beendet oder fand nicht nicht).
<?php
// EN-US: Include at the beginning of the first file to be interpreted, on the WEB server use TICK sparingly
// PT-BR: Incluir no início do primeiro arquivo a ser interpretado, no servidor WEB use o TICK com moderação
declare (ticks= 1 );
require_once " lib/code.php " ;
echo " Start " , PHP_EOL ;
$ counter = 1 ;
$ uid = setInterval ( function () use (& $ counter ) {
echo " Counter: " , $ counter ++, PHP_EOL ;
}, 100 );
setTimeout ( function () {
echo " Half of the increments " , PHP_EOL ;
}, 1000 );
setTimeout ( function () use ( $ uid ) {
echo " Stopping the counter " , PHP_EOL ;
clearInterval ( $ uid );
}, 2000 );
echo " Processing... " , PHP_EOL ;
// EN-US: Include after timed calls
// PT-BR: Incluir após chamadas programadas (agendadas)
$ count = workWait ( function () { usleep ( 1 ); });
echo " workRun has been run $ {count} times " , PHP_EOL ;
echo " End " , PHP_EOL ; then(callback) Methode, die aufgelöst werden, wenn Versprechen gelöst werden. callback wird ausgeführt und empfangen als Parameter resolve
catch(callback) -Methode, die als Versprechen abgelehnt wird. callback wird ausgeführt und empfangen als Parameter den Wert, der die reject übergeben hat.
finally(callback) Methode, die nach einem Versprechen aufgelöst oder abgelehnt wurde, wodurch die Ausführung des als Parameters informierten callback ausgelöst wird.
<?php
// EN-US: Include at the beginning of the first file to be interpreted, on the WEB server use TICK sparingly
// PT-BR: Incluir no início do primeiro arquivo a ser interpretado, no servidor WEB use o TICK com moderação
declare (ticks= 1 );
require_once " lib/code.php " ;
echo " Start " , PHP_EOL ;
$ promise = new Promise ( function ( $ resolve , $ reject ) {
$ call = rand ( 0 , 1 ) ? $ resolve : $ reject ;
setTimeout ( function () use ( $ call ) {
$ call ( " message " );
}, 1000 );
});
function info_promise () {
global $ promise ;
echo " > monitor: " , $ promise -> getMonitor (), PHP_EOL ;
echo " > state: " , $ promise -> getState (), PHP_EOL ;
}
info_promise ();
$ promise -> then ( function ( $ result ) {
echo " then ( $ {result} ) " , PHP_EOL ;
info_promise ();
})-> catch ( function ( $ error ) {
echo " catch ( $ {error} ) " , PHP_EOL ;
info_promise ();
})-> finally ( function () {
echo " finally " , PHP_EOL ;
info_promise ();
});
echo " Processing... " , PHP_EOL ;
for ( $ counter = 0 ; $ counter < 10 ; $ counter ++) {
echo " Counter: $ {counter}" , PHP_EOL ;
usleep ( 200000 );
}
// EN-US: Include after timed calls
// PT-BR: Incluir após chamadas programadas (agendadas)
$ count = workWait ( function () { usleep ( 1 ); });
echo " workRun has been run $ {count} times " , PHP_EOL ;
echo " End " , PHP_EOL ;