Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
docs: update
  • Loading branch information
tstelzer committed Jul 9, 2022
commit 5c827a33785f36f0817f2ee5c3143eee49bd0c43
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type * as core from '@contentlayer/core'
import type { PosixFilePath } from '@contentlayer/utils'
import { asMutableArray, posixFilePath } from '@contentlayer/utils'
import type { HasConsole } from '@contentlayer/utils/effect'
import { Chunk, E, HashMap, O, Option, OT, pipe, T, These, Tp } from '@contentlayer/utils/effect'
import { Chunk, E, O, Option, OT, pipe, T, These, Tp } from '@contentlayer/utils/effect'
import { fs } from '@contentlayer/utils/node'
import glob from 'fast-glob'
import * as os from 'node:os'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { provideDummyTracing, provideJaegerTracing } from '@contentlayer/utils'
import { provideJaegerTracing } from '@contentlayer/utils'
import { pipe, provideConsole, T } from '@contentlayer/utils/effect'
import type { _A, _E } from '@effect-ts/core/Utils'
import * as os from 'node:os'
Expand All @@ -14,6 +14,7 @@ export type Either<E, A> = Left<E, A> | Right<E, A>

type DTO = Either<_E<ReturnType<F>>, _A<ReturnType<F>>>

// TODO: generalize codec / serializing
// FIXME: naming
export function fromWorkerPool(): F {
const cores = os.cpus().length
Expand All @@ -24,7 +25,7 @@ export function fromWorkerPool(): F {
//
// via https://github.com/piscinajs/piscina#queue-size
maxQueue: cores ** cores,
// by default, this is cores * 1.5
// FIXME: on the default, (#cores * 1.5), this lead to memory issues that caused a thread panic
maxThreads: cores,
// FIXME: get path dynamically
filename:
Expand All @@ -34,7 +35,7 @@ export function fromWorkerPool(): F {
return (payload) =>
pipe(
// host -> worker
T.succeedWith(() => JSON.stringify(payload, null, 2)),
T.succeedWith(() => JSON.stringify(payload)),
T.chain((value) => T.promise<string>(() => pool.run(value, { name: 'makeCacheItemFromFilePath' }))),
// worker -> host
T.chain((value) => T.succeedWith<DTO>(() => JSON.parse(value))),
Expand Down Expand Up @@ -62,6 +63,6 @@ export function makeCacheItemFromFilePath(payload: string): Promise<string> {
provideConsole,
provideJaegerTracing('worker'),
T.runPromise,
(p) => p.then((value) => JSON.stringify(value, null, 2)),
(p) => p.then((value) => JSON.stringify(value)),
)
}