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

                    Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                    Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                    How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page