andywer/threads.js

View on GitHub

Showing 35 of 37 total issues

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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            errors<ThreadT extends ThreadType>(thread: ThreadT): Observable<Error> {
              return thread[$errors] || fail("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")
            },
          Severity: Minor
          Found in src/master/thread.ts and 1 other location - About 50 mins to fix
          src/master/thread.ts on lines 18..20

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 52.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            events<ThreadT extends ThreadType>(thread: ThreadT): Observable<WorkerEvent> {
              return thread[$events] || fail("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")
            },
          Severity: Minor
          Found in src/master/thread.ts and 1 other location - About 50 mins to fix
          src/master/thread.ts on lines 14..16

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 52.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          describe("threads webpack browser bundle with inlined worker", function() {
            this.timeout(80000)
          
            it("works fine", async function() {
              const bundle = require("./dist/app-inlined.web/main")
          Severity: Minor
          Found in test-tooling/webpack/webpack.chromium.mocha.ts and 1 other location - About 45 mins to fix
          test-tooling/webpack/webpack.chromium.mocha.ts on lines 4..11

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 50.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          describe("threads webpack browser bundle", function() {
            this.timeout(80000)
          
            it("works fine", async function() {
              const bundle = require("./dist/app.web/main")
          Severity: Minor
          Found in test-tooling/webpack/webpack.chromium.mocha.ts and 1 other location - About 45 mins to fix
          test-tooling/webpack/webpack.chromium.mocha.ts on lines 13..20

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 50.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          const isUncaughtErrorMessage = (data: any): data is WorkerUncaughtErrorMessage => data && data.type === ("uncaughtError" as const)
          Severity: Minor
          Found in src/master/spawn.ts and 1 other location - About 30 mins to fix
          src/master/spawn.ts on lines 39..39

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 45.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          const isInitMessage = (data: any): data is WorkerInitMessage => data && data.type === ("init" as const)
          Severity: Minor
          Found in src/master/spawn.ts and 1 other location - About 30 mins to fix
          src/master/spawn.ts on lines 40..40

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 45.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          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