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 {
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> = []
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
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 {
- Read upRead up
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) => {
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.`)
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 {
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
- Read upRead up
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) {
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
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> = []
- Read upRead up
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)
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)) {
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,
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[] = []
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
}
- Read upRead up
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
- Read upRead up
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: [],
- Read upRead up
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
- Read upRead up
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)
- Read upRead up
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"