I know "cluster" and "child_process" can use multiple cores of a CPU so that we can achieve true parallel processing.
I also know that the async event loop is single-threaded so we can only achieve concurrency.
My question is about worker_threads:
假设我的电脑有 4 核 CPU 并且我正在执行一个 Nodejs 脚本。该脚本创建三个工作线程。
三个工作线程会利用CPU中剩余的3个核心来实现并行吗?
或者三个工作线程将只使用主核心而其余3个核心不被使用,就像事件循环一样?
我想在图表数据值发生变化时删除旧的 SVG 并创建一个新的 SVG。
import React, {useRef, useEffect, useState} from 'react'
import * as d3 from 'd3'
import { useSelector} from "react-redux";
const Barchart = () =>{
const chart = useRef(null);
const chart_data= useSelector(state => state.ChartReducer);
useEffect(() => {
let svg = d3.select(chart.current)
//code to create the chart
//
return () => {
//How to remove the old svg element from the ref chart.current?
//I tried
chart.current.removeChild() // This throws an error saying expects 1 argument got 0
}
},[chart_data]) …Run Code Online (Sandbox Code Playgroud)