Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Determine if emit should occur immediately or after event loop #39

Closed
kpdecker opened this issue Jul 28, 2014 · 2 comments
Closed

Determine if emit should occur immediately or after event loop #39

kpdecker opened this issue Jul 28, 2014 · 2 comments
Milestone

Comments

@kpdecker
Copy link
Contributor

        this.clock.restore();

        page = fruitLoops.page({
          userAgent: 'anything but android',
          url: {
            path: '/foo'
          },
          index: __dirname + '/artifacts/empty-page.html',
          loaded: function(page) {
            page.window.emit('events');
            page.window.$.ajax({
              url: 'http://localhost:' + server.info.port + '/script'
            });
          },
          callback: function(err, html) {
            should.not.exist(err);
            html.should.equal('<!doctype html>\n<html>\n  <body>foo<script>var $serverCache = {"http://localhost:' + server.info.port + '/script": {"data":"<script>test<\\/script>"}};</script></body>\n</html>\n');
            done();
          }
        });

Does not allow the ajax event to complete, while if the emit is moved after the event it does. This surprised me and we might want to move it to post event loop as this was my expectation and seems to match other libraries (ex hapi) as well.

@kpdecker
Copy link
Contributor Author

kpdecker commented Sep 2, 2014

The decision was made to allow the defer operations. All emit's will occur after the current event cycle. If a defer is done for ajax or pending events then anything created after the emit function call is made but prior to the next tick will continue the lifecycle of the page.

@kpdecker
Copy link
Contributor Author

kpdecker commented Sep 2, 2014

Released in 0.11.0

@kpdecker kpdecker modified the milestone: 1.0.0 Feb 13, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

1 participant