const DEVELOPER_INFO = [
" autor " => " Matheus Johann Araújo " ,
" country " => " Brasil " ,
" state " => " Pernambuco " ,
" date " => " 2022-03-12 "
]; callback用語は、関数のパラメーターとして過去の関数を意味します。これは関数によって呼び出されます。 PHPでは、 callbacksはchameableを意味するcallableタイプです。
Closureと呼ばれるクラスは、匿名関数とarrow functionsを表す責任があります(矢印関数)。
callbackは通常、パラメーターによって渡される名前のない機能(匿名または矢印関数)ですが、名前のある関数がパラメーターとして渡されるのを防ぐものはありません!
setInterval(callback, milliseconds)無限に通知された時間でコールバック関数を実行します。この関数は、 clearInterval関数で使用して実行行からsetIntervalを除去できるUIDを返します。
setTimeout(callback, milliseconds)一意の方法で通知された時間内にコールバック関数コールを実行します。この関数は、 clearTimeout関数で使用できるUIDを返し、実行ラインからsetTimeoutを削除します。
clearInterval(UID)情報に基づいたUIDを持つsetIntervalの将来の実行を完了します。関数はtrue (終了)またはfalseを返します(終了しなかったか、スケジュールされたタスクが見つかりませんでした)。
clearTimeout(UID)情報に基づいたUIDがあるsetTimeoutの将来の実行を完了します。関数はtrue (終了)またはfalseを返します(終了しなかったか、スケジュールされたタスクが見つかりませんでした)。
<?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 ;次に、 Promiseが解決されたときに呼び出されるthen(callback)メソッド。 callbackが実行され、パラメーターとして関数で渡される値resolve 。
Promiseが拒否されたときに呼び出されるcatch(callback)メソッド。 callbackが実行され、 reject関数で渡された値をパラメーターとして受信します。
最後に、約束が解決または拒否された後に呼び出されたfinally(callback)メソッドは、パラメーターとして通知されたcallbackの実行を起動します。
<?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 ;