为什么node.js不同时处理这两个函数/方法?

时间:2018-06-22 17:22:48

标签: node.js asynchronous

为什么节点不同时处理以下两种功能/方法?

add_filter( 'the_content', 'replace_content_in_category' );
function replace_content_in_category( $content ){
    if( is_single() && in_category( 'Uncategorized' ) ){
        $old_word = 'Listen Below';
        $new_word = 'Just Now';

        $content = str_replace( $old_word, $new_word, $content );
    }

    return $content;
}

2 个答案:

答案 0 :(得分:1)

通常在以下情况下,函数为non-blocking

  1. 当前执行请求外部服务,例如I / O或联网请求等。

  2. 将函数调用置于计时器上,以便稍后执行。

但是您的功能不是其中的任何一个。

答案 1 :(得分:0)

您没有在当前代码中发出任何异步请求。在节点中,除非另有说明,否则通常按顺序执行代码。

因此,循环首先完成运行,然后执行代码的最后一条语句。

相关问题