import * as tracing_1 from "../Tracing"
const fileName_1 = "(@effect-ts/system): _src/Layer/unsafe.ts"
import * as Tp from "../Collections/Immutable/Tuple"
import * as Ex from "../Exit"
import * as F from "../Fiber"
import { releaseAll, ReleaseMap, Running } from "../Managed/ReleaseMap"
import * as P from "../Promise"
import * as Ref from "../Ref"
import * as L from "./core"
import * as T from "./deps-effect"
export class MainProvider {
  constructor(allocate, release, provide) {
    this.allocate = allocate
    this.release = release
    this.provide = provide
  }
}
/**
 * Unsafely returns a `MainProvider` to be used in frontend-like
 * contexts where initialization needs to be global and sync
 */

export function unsafeMainProvider(self) {
  const promise = P.unsafeMake(F.None)
  const relMap = new ReleaseMap(Ref.unsafeMakeRef(new Running(0, new Map())))
  return new MainProvider(
    T.foldCauseM_(
      T.map_(
        T.provideSome_(
          L.build(self["+++"](L.identity())).effect,
          (r) => Tp.tuple(r, relMap),
          fileName_1 + ":32:21"
        ),
        (_) => _.get(1),
        fileName_1 + ":31:11"
      ),
      (cause) =>
        T.chain_(
          P.halt_(promise, cause),
          () => T.halt(cause, fileName_1 + ":39:70"),
          fileName_1 + ":39:57"
        ),
      (r) => P.succeed(r)(promise),
      fileName_1 + ":38:19"
    ),
    T.descriptorWith(
      (d) =>
        T.asUnit(
          releaseAll(Ex.interrupt(d.id), T.sequential, fileName_1 + ":44:17")(relMap),
          fileName_1 + ":44:74"
        ),
      fileName_1 + ":43:21"
    ),
    (self) =>
      T.chain_(
        P.await(promise),
        (env) => T.provide_(self, env, fileName_1 + ":46:60"),
        fileName_1 + ":46:23"
      )
  )
}
//# sourceMappingURL=unsafe.js.map
