diff --git a/src/promise/deferred_promise.cr b/src/promise/deferred_promise.cr index f7576aa..4a70c61 100644 --- a/src/promise/deferred_promise.cr +++ b/src/promise/deferred_promise.cr @@ -121,22 +121,10 @@ class Promise::DeferredPromise(Input) < Promise end # pause the current fiber and wait for the resolution to occur - def get - channel = Channel(Proc(Input)).new - - spawn do - self.then(->(result : Input) { - channel.send(->{ result }) - nil - }, ->(rejection : Exception) { - # We provide the type_var here as a hint to the compiler - # Most things work without it however Promise.all segfaults when not specified - channel.send(->{ raise rejection; self.type_var }) - nil - }) - end - - channel.receive.call + def get : Input + result = raw_value + raise result if result.is_a?(Exception) + result end def raw_value diff --git a/src/promise/rejected_promise.cr b/src/promise/rejected_promise.cr index e388c41..db2d440 100644 --- a/src/promise/rejected_promise.cr +++ b/src/promise/rejected_promise.cr @@ -3,7 +3,7 @@ class Promise::RejectedPromise(Input) < Promise::DeferredPromise(Input) super() end - def get + def get : Input raise @rejection end diff --git a/src/promise/resolved_promise.cr b/src/promise/resolved_promise.cr index 5011e92..9c27055 100644 --- a/src/promise/resolved_promise.cr +++ b/src/promise/resolved_promise.cr @@ -4,7 +4,7 @@ class Promise::ResolvedPromise(Input) < Promise::DeferredPromise(Input) end # get the value directly if the promise is resolved - def get + def get : Input @value end