-module(version_bump@task).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/version_bump/task.gleam").
-export([resolve/1, map/2, await/2, run/2]).
-export_type([task/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" A minimal cross-target async abstraction.\n"
"\n"
" `Task(a)` is a deferred computation yielding an `a`. On the JavaScript target\n"
" it is backed by a `Promise`; on the Erlang/BEAM target there are no promises,\n"
" so it is simply the eagerly-computed value (an identity \"monad\"). The\n"
" combinators have target-specific FFI implementations (`version_bump_task_ffi.erl` and\n"
" `version_bump_task_ffi.mjs`) so the rest of the pipeline can sequence asynchronous work\n"
" — chiefly the GitHub HTTP request — without caring which target it compiles\n"
" for.\n"
"\n"
" On Erlang every combinator runs immediately and synchronously; on JavaScript\n"
" they defer onto the microtask/promise queue.\n"
).
-type task(KMQ) :: any() | {gleam_phantom, KMQ}.
-file("src/version_bump/task.gleam", 20).
?DOC(" A task that is already complete with `value`.\n").
-spec resolve(KMR) -> task(KMR).
resolve(Value) ->
version_bump_task_ffi:resolve(Value).
-file("src/version_bump/task.gleam", 25).
?DOC(" Transform the eventual value of a task.\n").
-spec map(task(KMT), fun((KMT) -> KMV)) -> task(KMV).
map(Task, F) ->
version_bump_task_ffi:map(Task, F).
-file("src/version_bump/task.gleam", 30).
?DOC(" Chain a task-producing function onto a task (monadic bind / promise \"then\").\n").
-spec await(task(KMX), fun((KMX) -> task(KMZ))) -> task(KMZ).
await(Task, F) ->
version_bump_task_ffi:await(Task, F).
-file("src/version_bump/task.gleam", 36).
?DOC(
" Run a task for its effect once it settles, passing the value to `f`. On\n"
" Erlang this is immediate; on JavaScript `f` runs when the promise resolves.\n"
).
-spec run(task(KNC), fun((KNC) -> nil)) -> nil.
run(Task, F) ->
version_bump_task_ffi:run(Task, F).