mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-26 20:14:47 +01:00
Add uv_stop()
This commit is contained in:
parent
2b04d12970
commit
096eedc215
21
php_uv.c
21
php_uv.c
@ -2688,6 +2688,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_run, 0, 0, 1)
|
|||||||
ZEND_ARG_INFO(0, loop)
|
ZEND_ARG_INFO(0, loop)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
|
|
||||||
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_stop, 0, 0, 1)
|
||||||
|
ZEND_ARG_INFO(0, loop)
|
||||||
|
ZEND_END_ARG_INFO()
|
||||||
|
|
||||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_loop_delete, 0, 0, 1)
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_loop_delete, 0, 0, 1)
|
||||||
ZEND_ARG_INFO(0, loop)
|
ZEND_ARG_INFO(0, loop)
|
||||||
ZEND_END_ARG_INFO()
|
ZEND_END_ARG_INFO()
|
||||||
@ -3483,6 +3487,22 @@ PHP_FUNCTION(uv_run)
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ proto void uv_stop([resource $uv_loop])
|
||||||
|
*/
|
||||||
|
PHP_FUNCTION(uv_stop)
|
||||||
|
{
|
||||||
|
zval *zloop = NULL;
|
||||||
|
uv_loop_t *loop;
|
||||||
|
|
||||||
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
||||||
|
"|z",&zloop) == FAILURE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PHP_UV_FETCH_UV_DEFAULT_LOOP(loop, zloop);
|
||||||
|
uv_stop(loop);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ proto long uv_run_once([resource $uv_loop])
|
/* {{{ proto long uv_run_once([resource $uv_loop])
|
||||||
*/
|
*/
|
||||||
PHP_FUNCTION(uv_run_once)
|
PHP_FUNCTION(uv_run_once)
|
||||||
@ -6439,6 +6459,7 @@ static zend_function_entry uv_functions[] = {
|
|||||||
PHP_FE(uv_unref, arginfo_uv_unref)
|
PHP_FE(uv_unref, arginfo_uv_unref)
|
||||||
PHP_FE(uv_loop_new, NULL)
|
PHP_FE(uv_loop_new, NULL)
|
||||||
PHP_FE(uv_default_loop, NULL)
|
PHP_FE(uv_default_loop, NULL)
|
||||||
|
PHP_FE(uv_stop, arginfo_uv_stop)
|
||||||
PHP_FE(uv_run, arginfo_uv_run)
|
PHP_FE(uv_run, arginfo_uv_run)
|
||||||
PHP_FE(uv_run_once, arginfo_uv_run_once)
|
PHP_FE(uv_run_once, arginfo_uv_run_once)
|
||||||
PHP_FE(uv_ip4_addr, arginfo_uv_ip4_addr)
|
PHP_FE(uv_ip4_addr, arginfo_uv_ip4_addr)
|
||||||
|
26
tests/100-uv_stop.phpt
Executable file
26
tests/100-uv_stop.phpt
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
--TEST--
|
||||||
|
Test uv_stop ends loop execution
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$loop = uv_default_loop();
|
||||||
|
$timer = uv_timer_init();
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
uv_timer_start($timer, 10, 10, function($timer) use (&$i, $loop) {
|
||||||
|
echo "count: {$i}" . PHP_EOL;
|
||||||
|
$i++;
|
||||||
|
|
||||||
|
if ($i > 3) {
|
||||||
|
uv_stop($loop);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
uv_run();
|
||||||
|
|
||||||
|
echo "finished" . PHP_EOL;
|
||||||
|
--EXPECT--
|
||||||
|
count: 0
|
||||||
|
count: 1
|
||||||
|
count: 2
|
||||||
|
count: 3
|
||||||
|
finished
|
Loading…
Reference in New Issue
Block a user