Closed Validark closed 7 years ago
I still think the IsAttempt function is stupid and unnecessary. Here is what someone would have to code in order for it to be necessary:
local Try = require("Try")
local Try2 = require("Try2")
local Attempt1 = Try(wait, 0.5)
local Attempt2 = Try2(wait, 1)
Attempt2.Then(Attempt1, function()
end)
As far as I see it @GigsD4X, you still haven't given any reason why this would ever be necessary. IsAttempt
should be removed and replaced with the in-function logic I previously implemented.
@GigsD4X, please look at my above example and tell me why you insist on the necessity of the _IsAttempt
property and corresponding internal function
@Validark Sorry about the late response, but consider the following case:
ArbitraryScript.lua
local Try = require(game.ReplicatedStorage.TryLibrary)
local Library = require(ArbitraryLibrary)
Try(wait)
:Then(Library.GetSumLength)
:Then(print)
ArbitraryLibrary.lua
local Try = require(script.TryLibrary)
local Library = {}
local function Add(A, B)
return A + B
end
function Library.GetSumLength(A, B)
return Try(Add, A, B)
:Then(tostring)
:Then(string.len)
end
return Library
Since an attempt is returned by the attempted function as a result in Attempt.Results
, it will be picked up by the following lines in subsequent :Then
or :Catch
operations:
-- Enter new attempt context if received
local FirstArgument = self.Results[1];
if self.Success and IsAttempt(FirstArgument) then
self = FirstArgument;
end;
However, since the attempt containing an attempt in its results is always discarded (when self
is replaced by the first returned attempt at the beginning of Then
and Catch
operations), we should consider making Try
and Attempt.Then
return the first returned attempt for chaining, rather than the attempt that contains it. This would make :Then and :Catch calls use that attempt's library.
Even if we implemented it to use Then
and Catch
from the original library, the original library still needs to know what is a new attempt and what isn't
Not longer relevant
Function
andArguments
setting fromRetry