From b5ba4d9e3896658675a2d7329155f5f8a43648a2 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sun, 14 Apr 2024 19:08:40 +0530 Subject: [PATCH] fix(Future): polling is guaranteed to return generic type T --- lib/future.luau | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/future.luau b/lib/future.luau index 5e7c21b..766c4f4 100644 --- a/lib/future.luau +++ b/lib/future.luau @@ -4,16 +4,11 @@ local mod = require("../mod") local Signal = mod.signal type Signal = mod.Signal -local option = require("option") -type Option = option.Option -local Some = option.Some -local None = option.None - local Future = {} export type Status = "initialized" | "running" | "cancelled" | "done" export type Future = typeof(Future) & { _fn: (set: (value: T) -> ()) -> T, - _ret: T?, + _ret: T, _thread: thread, _spawnEvt: Signal<()>, _retEvt: Signal, @@ -40,7 +35,7 @@ function Future.new(fn: (...any) -> T, args: { any }) ) end -function Future.poll(self: Future): (Status, Option) +function Future.poll(self: Future): (Status, T) if self._status == "initialized" then self._retEvt:Connect(function(firedRet, status: Status) self._status = status @@ -66,8 +61,7 @@ function Future.poll(self: Future): (Status, Option) task.wait(0.01) end - local retOpt = if self._ret == nil then None() else Some(self._ret) - return self._status, retOpt + return self._status, self._ret end function Future.cancel(self: Future)