https://linen.dev logo
Join Discord
Powered by
# tink
  • f

    few-pizza-8232

    02/22/2023, 4:26 AM
    I'm working with tink.core and running into some issues with
    PromiseTrigger
    and
    FutureTrigger
    I have a UI object with callbacks for confirmation and cancellation. The code that sets it up looks like this:
    Copy code
    class PromptServer {
      public static function prompt() {
        final confirmOrCancel = // instantiate UI object
        final pt = Promise.trigger();
    
        confirmOrCancel.confirmationHandler = () -> {
          trace("confirmed");
          pt.trigger(Success("bar"));
        };
    
        confirmOrCancel.cancelHandler = () -> {
          trace("cancelled");
          pt.trigger(Failure(new Error(null, "foo")));
        };
    
        return pt.asPromise();
      }
    }
    Another class calls
    prompt()
    to try to pass along the
    Promise
    , like so:
    Copy code
    function showPrompt() {
        return PromptServer.prompt().next(val -> {
          trace(val);
          return val;
        });
      }
    The returntype of
    showPrompt()
    is
    Promise<String>
    , but when I trigger the confirmation handler, I only see the "confirmed" trace. When I step into
    pt.trigger
    , the
    CallbackList
    is empty. I've tried this with both
    Promise.trigger()
    and
    Future.trigger()
    to the same effect. Am I misusing something here, or misunderstanding something about how
    Future
    and
    Promise
    are supposed to function?
  • l

    little-activity-86808

    02/22/2023, 1:34 PM
    that might be what's happening with @await then too, I only get Success, never Failure
  • l

    little-activity-86808

    02/22/2023, 3:36 PM
    here's a simpler example, hangs on the @await the second time...
    Copy code
    package;
    
    using tink.CoreApi;
    
    @await class Futures
    {
        static function main()
        {
            var inst = new Futures();
        }
    
        function new()
        {
            init();
        }
    
        @async function init()
        {
            var s = @await successOrFailure(true);
            trace('Should return a true from Succed(true): $s');
            var f = @await successOrFailure(false);
            trace('Should return an Error from Failure: $f');
        } 
    
        function successOrFailure(succeed:Bool)
        {
            return Future.async(yield -> succeed ? yield(Success(true)) : yield(Failure(new Error(101,'I am failure.'))));
        }
    }
  • l

    little-activity-86808

    02/22/2023, 3:38 PM
    looks to be the same prob with the Promise/Future?
  • c

    cool-psychiatrist-49311

    02/22/2023, 9:48 PM
    .next() is only run for a success promise
  • c

    cool-psychiatrist-49311

    02/22/2023, 9:48 PM
    You need to .handle() the error
  • c

    cool-psychiatrist-49311

    02/22/2023, 9:49 PM
    In case of tink await, you need to try catch the error
  • l

    little-activity-86808

    02/23/2023, 7:18 AM
    ok, so in the example above, where I'm creating the error, yield is never called? Is that the .next()? How do I return the Failure with the Error in?
  • c

    cool-psychiatrist-49311

    02/23/2023, 7:39 AM
    Your yield part is ok
  • c

    cool-psychiatrist-49311

    02/23/2023, 7:40 AM
    You just need to try/catch the call site
  • c

    cool-psychiatrist-49311

    02/23/2023, 7:41 AM
    Simplest way here is to wrap the whole function body of init() in a try catch block
  • l

    little-activity-86808

    02/23/2023, 7:43 AM
    so there's no way of returning the Failure?
  • l

    little-activity-86808

    02/23/2023, 7:48 AM
    Copy code
    @async function init()
        {
            try
            {
                var s = @await successOrFailure(true);
                trace('Should return a true from Succed(true): $s');
                var f = @await successOrFailure(false);
                trace('Should return an Error from Failure: $f');
            }
            catch(e)
            {
                trace(e);
            }
        } 
    
        function successOrFailure(succeed:Bool):Surprise<Bool, Error>
        {
            return Future.async(yield -> succeed ? yield(Success(true)) : yield(Failure(throw new Error(101,'I am failure.'))));
        }
  • l

    little-activity-86808

    02/23/2023, 7:49 AM
    thanks, that traces the success call, then doesn't trace the lines after the second call which is caught int he catch block
  • l

    little-activity-86808

    02/23/2023, 7:49 AM
    I think I can work with that 😄
  • l

    little-activity-86808

    02/23/2023, 7:49 AM
    works without the throw in the Failure too
  • l

    little-activity-86808

    02/23/2023, 7:50 AM
    cool thanks kevin
  • f

    few-pizza-8232

    02/24/2023, 4:05 AM
    I see, I misunderstood it to be literally "do this next and return the result as a new `Promise`/`Future`". I hadn't wired up a
    handle
    on the other end because I was trying to get the callback to tell me it was doing anything before I even tried! A bit surprising that it doesn't trigger
    next
    callbacks if there's nothing to
    handle
    the final result, even if those have side effects. But I can understand the rationale.
  • c

    cool-musician-79004

    03/09/2023, 11:47 AM
    Hey! Any plan to update the library to use the new isOfType? I am getting this warning
    Copy code
    Warning : Std.is is deprecated. Use Std.isOfType instead.
  • e

    elegant-twilight-61392

    03/09/2023, 4:16 PM
    make a pr
  • c

    cool-musician-79004

    03/09/2023, 6:06 PM
    Do you think it will be reviewed? I opened an issue on January and don't get any response
  • e

    elegant-twilight-61392

    03/09/2023, 6:08 PM
    ¯\_(ツ)_/¯
  • a

    ambitious-knife-25690

    03/09/2023, 6:37 PM
    an issue vs a pr, and a particularly simple pr may have different results
  • c

    cool-musician-79004

    03/09/2023, 8:14 PM
    👍🏻
  • c

    cool-psychiatrist-49311

    03/13/2023, 1:12 PM
    I think you opened an issue in tink lang? That one is sort of obsolete unfortunately, because many functions are already built into the language itself.
  • c

    cool-psychiatrist-49311

    03/13/2023, 1:12 PM
    And yeah PR will be more welcome then issues in general
  • c

    cool-musician-79004

    03/14/2023, 6:35 AM
    > because many functions are already built into the language itself. That is something I thought... that a lot of things felt like were already solved by Haxe itself, but I had not enough experience with Haxe to decide for myself
  • l

    little-oxygen-79174

    03/18/2023, 9:49 PM
    It'd be nice if Tink Lang got a new major version that removes any deprecated syntax
  • s

    straight-twilight-37046

    03/20/2023, 4:46 AM
    https://tenor.com/view/pout-tinkerbell-cross-annoyed-vexed-gif-5740555
  • s

    straight-twilight-37046

    03/20/2023, 4:46 AM
    #579634919576436736erbell