andywer/threads.js

View on GitHub

Showing 20 of 37 total issues

File pool.ts has 292 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import DebugLogger from "debug"
import { multicast, Observable, Subject } from "observable-fns"
import { allSettled } from "../ponyfills"
import { defaultPoolSize } from "./implementation"
import {
Severity: Minor
Found in src/master/pool.ts - About 3 hrs to fix

    Function initTinyWorker has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function initTinyWorker(): ImplementationExport {
      const TinyWorker = require("tiny-worker")
    
      let allWorkers: Array<typeof TinyWorker> = []
    
    
    Severity: Major
    Found in src/master/implementation.node.ts - About 2 hrs to fix

      Function initWorkerThreadsWorker has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function initWorkerThreadsWorker(): ImplementationExport {
        // Webpack hack
        const NativeWorker = typeof __non_webpack_require__ === "function"
          ? __non_webpack_require__("worker_threads").Worker
          : eval("require")("worker_threads").Worker
      Severity: Major
      Found in src/master/implementation.node.ts - About 2 hrs to fix

        Function selectWorkerImplementation has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        function selectWorkerImplementation(): ImplementationExport {
          if (typeof Worker === "undefined") {
            // Might happen on Safari, for instance
            // The idea is to only fail if the constructor is actually used
            return class NoWebWorker {
        Severity: Minor
        Found in src/master/implementation.browser.ts - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function createObservableForJob has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function createObservableForJob<ResultType>(worker: WorkerType, jobUID: number): Observable<ResultType> {
          return new Observable(observer => {
            let asyncType: "observable" | "promise" | undefined
        
            const messageHandler = ((event: MessageEvent) => {
        Severity: Minor
        Found in src/master/invocation-proxy.ts - About 1 hr to fix

          Function queue has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public queue(taskFunction: TaskRunFunction<ThreadType, any>) {
              const { maxQueuedJobs = Infinity } = this.options
          
              if (this.isClosing) {
                throw Error(`Cannot schedule pool tasks after terminate() has been called.`)
          Severity: Minor
          Found in src/master/pool.ts - About 1 hr to fix

            Function selectWorkerImplementation has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function selectWorkerImplementation(): ImplementationExport {
              if (typeof Worker === "undefined") {
                // Might happen on Safari, for instance
                // The idea is to only fail if the constructor is actually used
                return class NoWebWorker {
            Severity: Minor
            Found in src/master/implementation.browser.ts - About 1 hr to fix

              Function initWorkerThreadsWorker has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

              function initWorkerThreadsWorker(): ImplementationExport {
                // Webpack hack
                const NativeWorker = typeof __non_webpack_require__ === "function"
                  ? __non_webpack_require__("worker_threads").Worker
                  : eval("require")("worker_threads").Worker
              Severity: Minor
              Found in src/master/implementation.node.ts - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function expose has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function expose(exposed: WorkerFunction | WorkerModule<any>) {
                if (!Implementation.isWorkerRuntime()) {
                  throw Error("expose() called in the master thread.")
                }
                if (exposeCalled) {
              Severity: Minor
              Found in src/worker/index.ts - About 1 hr to fix

                Function then has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  public then<TResult1 = T, TResult2 = never>(
                    onFulfilledRaw?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
                    onRejectedRaw?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
                  ): Promise<TResult1 | TResult2> {
                    const onFulfilled: OnFulfilled<T, TResult1> = onFulfilledRaw || returnInput as any
                Severity: Minor
                Found in src/observable-promise.ts - About 1 hr to fix

                  Function initTinyWorker has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function initTinyWorker(): ImplementationExport {
                    const TinyWorker = require("tiny-worker")
                  
                    let allWorkers: Array<typeof TinyWorker> = []
                  
                  
                  Severity: Minor
                  Found in src/master/implementation.node.ts - About 1 hr to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function runFunction has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  async function runFunction(jobUID: number, fn: WorkerFunction, args: any[]) {
                    let syncResult: any
                  
                    try {
                      syncResult = fn(...args)
                  Severity: Minor
                  Found in src/worker/index.ts - About 1 hr to fix

                    Function messageHandler has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        const messageHandler = ((event: MessageEvent) => {
                          debugMessages("Message from worker:", event.data)
                          if (!event.data || event.data.uid !== jobUID) return
                    
                          if (isJobStartMessage(event.data)) {
                    Severity: Minor
                    Found in src/master/invocation-proxy.ts - About 1 hr to fix

                      Function createEventObservable has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function createEventObservable(worker: WorkerType, workerTermination: Promise<any>): Observable<WorkerEvent> {
                        return new Observable<WorkerEvent>(observer => {
                          const messageHandler = ((messageEvent: MessageEvent) => {
                            const workerEvent: WorkerMessageEvent<any> = {
                              type: WorkerEventType.message,
                      Severity: Minor
                      Found in src/master/spawn.ts - About 1 hr to fix

                        Function settled has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          public async settled(allowResolvingImmediately: boolean = false): Promise<Error[]> {
                            const getCurrentlyRunningTasks = () => flatMap(this.workers, worker => worker.runningTasks)
                        
                            const taskFailures: Error[] = []
                        
                        
                        Severity: Minor
                        Found in src/master/pool.ts - About 1 hr to fix

                          Function detectTsNode has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function detectTsNode() {
                            if (typeof __non_webpack_require__ === "function") {
                              // Webpack build: => No ts-node required or possible
                              return false
                            }
                          Severity: Minor
                          Found in src/master/implementation.node.ts - About 35 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Function stringifyWebpackError has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                          const stringifyWebpackError = (error: any) =>
                            !error
                            ? ""
                            : typeof error.stack === "string"
                            ? error.stack
                          Severity: Minor
                          Found in test-tooling/webpack/webpack.test.ts - About 25 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Function prepareArguments has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function prepareArguments(rawArgs: any[]): { args: any[], transferables: Transferable[] } {
                            if (rawArgs.length === 0) {
                              // Exit early if possible
                              return {
                                args: [],
                          Severity: Minor
                          Found in src/master/invocation-proxy.ts - About 25 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Function isWorkerRuntime has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                          export function isWorkerRuntime() {
                            if (isTinyWorker) {
                              return typeof self !== "undefined" && self.postMessage ? true : false
                            } else {
                              // Webpack hack
                          Severity: Minor
                          Found in src/master/implementation.node.ts - About 25 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Function runFunction has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                          async function runFunction(jobUID: number, fn: WorkerFunction, args: any[]) {
                            let syncResult: any
                          
                            try {
                              syncResult = fn(...args)
                          Severity: Minor
                          Found in src/worker/index.ts - About 25 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Severity
                          Category
                          Status
                          Source
                          Language