Problem with Mojo::IOLoop timer before redirectOutput command to socket without buffering using Mojo::IOLoopWhy separate routing and controller actions in mojolicious?Route to static file in MojoMojo IOLoop blocks app when ranShutting down a Mojo::IOLoop recurring event connected to a Mojo websocketMojo::UserAgent clear session dataMojo::DOM manipulationSequentioal requests with Mojo::IOLoop::Delayunderstanding Mojo::IOLoop recurring and subprocessCan I limit the number of connections for Mojo::IOLoop?

Is a naturally all "male" species possible?

Books on the History of math research at European universities

Lifted its hind leg on or lifted its hind leg towards?

Who must act to prevent Brexit on March 29th?

How will losing mobility of one hand affect my career as a programmer?

Is there an Impartial Brexit Deal comparison site?

Female=gender counterpart?

For airliners, what prevents wing strikes on landing in bad weather?

Is there an wasy way to program in Tikz something like the one in the image?

Why are all the doors on Ferenginar (the Ferengi home world) far shorter than the average Ferengi?

Why isn't KTEX's runway designation 10/28 instead of 9/27?

Blender - show edges angles “direction”

Identify a stage play about a VR experience in which participants are encouraged to simulate performing horrific activities

My boss asked me to take a one-day class, then signs it up as a day off

Simple recursive Sudoku solver

Are Warlocks Arcane or Divine?

Proof of Lemma: Every integer can be written as a product of primes

Superhero words!

Why is delta-v is the most useful quantity for planning space travel?

Pronouncing Homer as in modern Greek

Simulating a probability of 1 of 2^N with less than N random bits

Can the electrostatic force be infinite in magnitude?

A workplace installs custom certificates on personal devices, can this be used to decrypt HTTPS traffic?

Is it legal to discriminate due to the medicine used to treat a medical condition?



Problem with Mojo::IOLoop timer before redirect


Output command to socket without buffering using Mojo::IOLoopWhy separate routing and controller actions in mojolicious?Route to static file in MojoMojo IOLoop blocks app when ranShutting down a Mojo::IOLoop recurring event connected to a Mojo websocketMojo::UserAgent clear session dataMojo::DOM manipulationSequentioal requests with Mojo::IOLoop::Delayunderstanding Mojo::IOLoop recurring and subprocessCan I limit the number of connections for Mojo::IOLoop?













1















i have a sub in my Mojolicious Controller which is called when a csv file is uploaded through a http post.
After the file is uploaded, a message gets rendered that say "you will be redirected in x seconds".
so i want to implement Mojo::IOLoop::Delay and as callback i use the redirect statement. But i get the following error by Morbo:



Mojo::Reactor::EV: Timer failed: Transaction already destroyed at /usr/local/share/perl/5.22.1/Mojolicious/Plugin/DefaultHelpers.pm line 168.


controller code:



sub upload 
my $self = shift;
# Check file size
return $self->render(text => 'File is too big.', status => 200)
if $self->req->is_limit_exceeded;

# Process uploaded file
return $self->redirect_to('/') unless my $newCsv = $self->param('fileToUpload');
my $size = $newCsv->size;
my $name = $newCsv->filename;
my $delay = 2;
$self->render(text => "Thanks for uploading $size byte file $name.<br>
You will be redirected in $delay seconds");
Mojo::IOLoop->timer($delay => sub
$self->redirect_to('/');
);



relevant routes:



$r->get('/')->to(controller => 'main', action => 'index');
$r->post('/uploadCsv')->to(controller => 'main', action => 'upload')->name('uploadCsv');


Thank you in advance










share|improve this question




























    1















    i have a sub in my Mojolicious Controller which is called when a csv file is uploaded through a http post.
    After the file is uploaded, a message gets rendered that say "you will be redirected in x seconds".
    so i want to implement Mojo::IOLoop::Delay and as callback i use the redirect statement. But i get the following error by Morbo:



    Mojo::Reactor::EV: Timer failed: Transaction already destroyed at /usr/local/share/perl/5.22.1/Mojolicious/Plugin/DefaultHelpers.pm line 168.


    controller code:



    sub upload 
    my $self = shift;
    # Check file size
    return $self->render(text => 'File is too big.', status => 200)
    if $self->req->is_limit_exceeded;

    # Process uploaded file
    return $self->redirect_to('/') unless my $newCsv = $self->param('fileToUpload');
    my $size = $newCsv->size;
    my $name = $newCsv->filename;
    my $delay = 2;
    $self->render(text => "Thanks for uploading $size byte file $name.<br>
    You will be redirected in $delay seconds");
    Mojo::IOLoop->timer($delay => sub
    $self->redirect_to('/');
    );



    relevant routes:



    $r->get('/')->to(controller => 'main', action => 'index');
    $r->post('/uploadCsv')->to(controller => 'main', action => 'upload')->name('uploadCsv');


    Thank you in advance










    share|improve this question


























      1












      1








      1








      i have a sub in my Mojolicious Controller which is called when a csv file is uploaded through a http post.
      After the file is uploaded, a message gets rendered that say "you will be redirected in x seconds".
      so i want to implement Mojo::IOLoop::Delay and as callback i use the redirect statement. But i get the following error by Morbo:



      Mojo::Reactor::EV: Timer failed: Transaction already destroyed at /usr/local/share/perl/5.22.1/Mojolicious/Plugin/DefaultHelpers.pm line 168.


      controller code:



      sub upload 
      my $self = shift;
      # Check file size
      return $self->render(text => 'File is too big.', status => 200)
      if $self->req->is_limit_exceeded;

      # Process uploaded file
      return $self->redirect_to('/') unless my $newCsv = $self->param('fileToUpload');
      my $size = $newCsv->size;
      my $name = $newCsv->filename;
      my $delay = 2;
      $self->render(text => "Thanks for uploading $size byte file $name.<br>
      You will be redirected in $delay seconds");
      Mojo::IOLoop->timer($delay => sub
      $self->redirect_to('/');
      );



      relevant routes:



      $r->get('/')->to(controller => 'main', action => 'index');
      $r->post('/uploadCsv')->to(controller => 'main', action => 'upload')->name('uploadCsv');


      Thank you in advance










      share|improve this question
















      i have a sub in my Mojolicious Controller which is called when a csv file is uploaded through a http post.
      After the file is uploaded, a message gets rendered that say "you will be redirected in x seconds".
      so i want to implement Mojo::IOLoop::Delay and as callback i use the redirect statement. But i get the following error by Morbo:



      Mojo::Reactor::EV: Timer failed: Transaction already destroyed at /usr/local/share/perl/5.22.1/Mojolicious/Plugin/DefaultHelpers.pm line 168.


      controller code:



      sub upload 
      my $self = shift;
      # Check file size
      return $self->render(text => 'File is too big.', status => 200)
      if $self->req->is_limit_exceeded;

      # Process uploaded file
      return $self->redirect_to('/') unless my $newCsv = $self->param('fileToUpload');
      my $size = $newCsv->size;
      my $name = $newCsv->filename;
      my $delay = 2;
      $self->render(text => "Thanks for uploading $size byte file $name.<br>
      You will be redirected in $delay seconds");
      Mojo::IOLoop->timer($delay => sub
      $self->redirect_to('/');
      );



      relevant routes:



      $r->get('/')->to(controller => 'main', action => 'index');
      $r->post('/uploadCsv')->to(controller => 'main', action => 'upload')->name('uploadCsv');


      Thank you in advance







      perl mojolicious morbo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 18:00









      Grinnz

      3,311514




      3,311514










      asked Mar 8 at 8:10









      ChrisChris

      376114




      376114






















          2 Answers
          2






          active

          oldest

          votes


















          1














          upload returns after Mojo::IOLoop->timer and nothing waits for the timer. You can try using Mojo::IOLoop->delay and $delay->wait instead. But I am not sure how it works. So it might be equivalent to just sleep.



          Do you really need to redirect from perl code? You can render some js with setTimeout for the same effect.



          In fact I would recommend moving all text and redirecting to js and render only json with some status information inside upload. So you can implement better UI with error handling.






          share|improve this answer






























            2














            redirect_to is effectively a render that renders a HTTP 302 response to redirect. You cannot render twice, so even if you keep the transaction around until the redirect_to call, it would have already rendered the page. So there are two actual options for what you are trying to do; render a page with javascript that will perform the redirect after a timeout, or render an HTML page with a meta refresh tag which will cause the page to redirect after a delay. This MDN page discusses both approaches.






            share|improve this answer























            • thanks for your answer. I have chosen the 3rd solution :) : i implemented a JS-script with a timeout in my .html. do you think this solution is practicable too, or it's not "the best" solution?

              – Chris
              Mar 8 at 20:33











            • @Chris I think it's fine for what you want to accomplish, the only benefit of the meta-refresh approach is that it doesn't require the user to enable javascript.

              – Grinnz
              Mar 8 at 20:36












            • i see, thanks again for your support!

              – Chris
              Mar 8 at 20:42










            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55059064%2fproblem-with-mojoioloop-timer-before-redirect%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            upload returns after Mojo::IOLoop->timer and nothing waits for the timer. You can try using Mojo::IOLoop->delay and $delay->wait instead. But I am not sure how it works. So it might be equivalent to just sleep.



            Do you really need to redirect from perl code? You can render some js with setTimeout for the same effect.



            In fact I would recommend moving all text and redirecting to js and render only json with some status information inside upload. So you can implement better UI with error handling.






            share|improve this answer



























              1














              upload returns after Mojo::IOLoop->timer and nothing waits for the timer. You can try using Mojo::IOLoop->delay and $delay->wait instead. But I am not sure how it works. So it might be equivalent to just sleep.



              Do you really need to redirect from perl code? You can render some js with setTimeout for the same effect.



              In fact I would recommend moving all text and redirecting to js and render only json with some status information inside upload. So you can implement better UI with error handling.






              share|improve this answer

























                1












                1








                1







                upload returns after Mojo::IOLoop->timer and nothing waits for the timer. You can try using Mojo::IOLoop->delay and $delay->wait instead. But I am not sure how it works. So it might be equivalent to just sleep.



                Do you really need to redirect from perl code? You can render some js with setTimeout for the same effect.



                In fact I would recommend moving all text and redirecting to js and render only json with some status information inside upload. So you can implement better UI with error handling.






                share|improve this answer













                upload returns after Mojo::IOLoop->timer and nothing waits for the timer. You can try using Mojo::IOLoop->delay and $delay->wait instead. But I am not sure how it works. So it might be equivalent to just sleep.



                Do you really need to redirect from perl code? You can render some js with setTimeout for the same effect.



                In fact I would recommend moving all text and redirecting to js and render only json with some status information inside upload. So you can implement better UI with error handling.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 8:30









                UjinT34UjinT34

                1,766112




                1,766112























                    2














                    redirect_to is effectively a render that renders a HTTP 302 response to redirect. You cannot render twice, so even if you keep the transaction around until the redirect_to call, it would have already rendered the page. So there are two actual options for what you are trying to do; render a page with javascript that will perform the redirect after a timeout, or render an HTML page with a meta refresh tag which will cause the page to redirect after a delay. This MDN page discusses both approaches.






                    share|improve this answer























                    • thanks for your answer. I have chosen the 3rd solution :) : i implemented a JS-script with a timeout in my .html. do you think this solution is practicable too, or it's not "the best" solution?

                      – Chris
                      Mar 8 at 20:33











                    • @Chris I think it's fine for what you want to accomplish, the only benefit of the meta-refresh approach is that it doesn't require the user to enable javascript.

                      – Grinnz
                      Mar 8 at 20:36












                    • i see, thanks again for your support!

                      – Chris
                      Mar 8 at 20:42















                    2














                    redirect_to is effectively a render that renders a HTTP 302 response to redirect. You cannot render twice, so even if you keep the transaction around until the redirect_to call, it would have already rendered the page. So there are two actual options for what you are trying to do; render a page with javascript that will perform the redirect after a timeout, or render an HTML page with a meta refresh tag which will cause the page to redirect after a delay. This MDN page discusses both approaches.






                    share|improve this answer























                    • thanks for your answer. I have chosen the 3rd solution :) : i implemented a JS-script with a timeout in my .html. do you think this solution is practicable too, or it's not "the best" solution?

                      – Chris
                      Mar 8 at 20:33











                    • @Chris I think it's fine for what you want to accomplish, the only benefit of the meta-refresh approach is that it doesn't require the user to enable javascript.

                      – Grinnz
                      Mar 8 at 20:36












                    • i see, thanks again for your support!

                      – Chris
                      Mar 8 at 20:42













                    2












                    2








                    2







                    redirect_to is effectively a render that renders a HTTP 302 response to redirect. You cannot render twice, so even if you keep the transaction around until the redirect_to call, it would have already rendered the page. So there are two actual options for what you are trying to do; render a page with javascript that will perform the redirect after a timeout, or render an HTML page with a meta refresh tag which will cause the page to redirect after a delay. This MDN page discusses both approaches.






                    share|improve this answer













                    redirect_to is effectively a render that renders a HTTP 302 response to redirect. You cannot render twice, so even if you keep the transaction around until the redirect_to call, it would have already rendered the page. So there are two actual options for what you are trying to do; render a page with javascript that will perform the redirect after a timeout, or render an HTML page with a meta refresh tag which will cause the page to redirect after a delay. This MDN page discusses both approaches.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 8 at 17:52









                    GrinnzGrinnz

                    3,311514




                    3,311514












                    • thanks for your answer. I have chosen the 3rd solution :) : i implemented a JS-script with a timeout in my .html. do you think this solution is practicable too, or it's not "the best" solution?

                      – Chris
                      Mar 8 at 20:33











                    • @Chris I think it's fine for what you want to accomplish, the only benefit of the meta-refresh approach is that it doesn't require the user to enable javascript.

                      – Grinnz
                      Mar 8 at 20:36












                    • i see, thanks again for your support!

                      – Chris
                      Mar 8 at 20:42

















                    • thanks for your answer. I have chosen the 3rd solution :) : i implemented a JS-script with a timeout in my .html. do you think this solution is practicable too, or it's not "the best" solution?

                      – Chris
                      Mar 8 at 20:33











                    • @Chris I think it's fine for what you want to accomplish, the only benefit of the meta-refresh approach is that it doesn't require the user to enable javascript.

                      – Grinnz
                      Mar 8 at 20:36












                    • i see, thanks again for your support!

                      – Chris
                      Mar 8 at 20:42
















                    thanks for your answer. I have chosen the 3rd solution :) : i implemented a JS-script with a timeout in my .html. do you think this solution is practicable too, or it's not "the best" solution?

                    – Chris
                    Mar 8 at 20:33





                    thanks for your answer. I have chosen the 3rd solution :) : i implemented a JS-script with a timeout in my .html. do you think this solution is practicable too, or it's not "the best" solution?

                    – Chris
                    Mar 8 at 20:33













                    @Chris I think it's fine for what you want to accomplish, the only benefit of the meta-refresh approach is that it doesn't require the user to enable javascript.

                    – Grinnz
                    Mar 8 at 20:36






                    @Chris I think it's fine for what you want to accomplish, the only benefit of the meta-refresh approach is that it doesn't require the user to enable javascript.

                    – Grinnz
                    Mar 8 at 20:36














                    i see, thanks again for your support!

                    – Chris
                    Mar 8 at 20:42





                    i see, thanks again for your support!

                    – Chris
                    Mar 8 at 20:42

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55059064%2fproblem-with-mojoioloop-timer-before-redirect%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme