77
88prelude
99public import Init.System.Promise
10+ public meta import Lean.Elab.Term
1011
1112public section
1213
@@ -306,11 +307,21 @@ def block (x : AsyncTask α) : IO α :=
306307 | .ok a => return a
307308 | .error e => .error e
308309
310+ syntax "currFunctionError%" : term
311+
312+ elab_rules : term
313+ | `(currFunctionError%) => do
314+ let declName? ← Lean.Elab.Term.getDeclName?
315+ let fnName := match declName? with
316+ | some name => s! "the promise linked to `{ name} ` was dropped"
317+ | none => "the promise linked to the Async was dropped"
318+ Lean.Elab.Term.elabTerm (← `($(Lean.quote fnName))) none
319+
309320/--
310321Create an `AsyncTask` that resolves to the value of `x`.
311322-/
312323@[inline]
313- def ofPromise (x : IO.Promise (Except IO.Error α)) (error : String := "the promise linked to the Async Task was dropped" ) : AsyncTask α :=
324+ def ofPromise (x : IO.Promise (Except IO.Error α)) (error : String := by exact currFunctionError% ) : AsyncTask α :=
314325 x.result?.map fun
315326 | none => .error error
316327 | some res => res
@@ -319,7 +330,7 @@ def ofPromise (x : IO.Promise (Except IO.Error α)) (error : String := "the prom
319330Create an `AsyncTask` that resolves to the value of `x`.
320331-/
321332@[inline]
322- def ofPurePromise (x : IO.Promise α) (error : String := "the promise linked to the Async Task was dropped" ) : AsyncTask α :=
333+ def ofPurePromise (x : IO.Promise α) (error : String := by exact currFunctionError% ) : AsyncTask α :=
323334 x.result?.map (sync := true ) fun
324335 | none => .error error
325336 | some res => pure res
@@ -884,7 +895,7 @@ protected def block (x : Async α) (prio := Task.Priority.default) : IO α :=
884895Converts `Promise` into `Async`.
885896-/
886897@[inline]
887- protected def ofPromise (task : IO (IO.Promise (Except IO.Error α))) (error : String := "the promise linked to the Async was dropped" ) : Async α := do
898+ protected def ofPromise (task : IO (IO.Promise (Except IO.Error α))) (error : String := by exact currFunctionError% ) : Async α := do
888899 match ← task.toBaseIO with
889900 | .ok data => pure (f := BaseIO) <| MaybeTask.ofTask <| data.result?.map fun
890901 | none => .error error
@@ -925,7 +936,7 @@ protected def ofTask (task : Task α) : Async α := do
925936Converts `IO (IO.Promise α)` to `Async`.
926937-/
927938@[inline]
928- protected def ofPurePromise (task : IO (IO.Promise α)) (error : String := "the promise linked to the Async was dropped" ) : Async α := show BaseIO _ from do
939+ protected def ofPurePromise (task : IO (IO.Promise α)) (error : String := by exact currFunctionError% ) : Async α := show BaseIO _ from do
929940 match ← task.toBaseIO with
930941 | .ok data => pure <| MaybeTask.ofTask <| data.result?.map fun
931942 | none => .error error
0 commit comments