Skip to content

Instantly share code, notes, and snippets.

@tim-smart
Created May 8, 2026 10:49
Show Gist options
  • Select an option

  • Save tim-smart/49aee31e9fe80719cdb17e58e4be156b to your computer and use it in GitHub Desktop.

Select an option

Save tim-smart/49aee31e9fe80719cdb17e58e4be156b to your computer and use it in GitHub Desktop.
import { NodeRuntime, NodeServices } from "@effect/platform-node"
import { Console, Effect, Stream } from "effect"
import { ChildProcess } from "effect/unstable/process"
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner"
Effect.gen(function*() {
const spawner = yield* ChildProcessSpawner
const handle = yield* spawner.spawn(ChildProcess.make`git diff`)
yield* handle.stdout.pipe(
Stream.decodeText,
Stream.mkString
)
}).pipe(
Console.withTime("effect"),
Effect.scoped,
Effect.provide(NodeServices.layer),
NodeRuntime.runMain
)
import * as CP from "node:child_process"
async function main() {
console.time("node")
const handle = CP.spawn("git", ["diff"])
handle.stdout.setEncoding("utf8")
let out = ""
await handle.stdout.forEach((data) => {
out += data
})
console.timeEnd("node")
}
main()
effect-smol git(main) node scratchpad/effect.ts
effect: 13.195ms
effect-smol git(main) node scratchpad/node.ts
node: 13.407ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment