comparison lib/js/urweb.js @ 1042:a8a825861397

Explicitly abort in-flight RPCs onunload
author Adam Chlipala <adamc@hcoop.net>
date Tue, 24 Nov 2009 09:24:25 -0500
parents 0d767c8d2923
children eaba663fd6aa
comparison
equal deleted inserted replaced
1041:0d767c8d2923 1042:a8a825861397
625 } 625 }
626 } 626 }
627 627
628 var sig = null; 628 var sig = null;
629 629
630 var unloading = false, inFlight = null;
631
632 function unload() {
633 unloading = true;
634
635 for (; inFlight; inFlight = inFlight.next) {
636 inFlight.data.abort();
637 }
638 }
639
630 function requestUri(xhr, uri, needsSig) { 640 function requestUri(xhr, uri, needsSig) {
641 if (unloading)
642 return;
643
631 xhr.open("POST", uri, true); 644 xhr.open("POST", uri, true);
632 645
633 if (client_id != null) { 646 if (client_id != null) {
634 xhr.setRequestHeader("UrWeb-Client", client_id.toString()); 647 xhr.setRequestHeader("UrWeb-Client", client_id.toString());
635 xhr.setRequestHeader("UrWeb-Pass", client_pass.toString()); 648 xhr.setRequestHeader("UrWeb-Pass", client_pass.toString());
640 whine("Missing cookie signature!"); 653 whine("Missing cookie signature!");
641 654
642 xhr.setRequestHeader("UrWeb-Sig", sig); 655 xhr.setRequestHeader("UrWeb-Sig", sig);
643 } 656 }
644 657
658 inFlight = cons(xhr, inFlight);
645 xhr.send(null); 659 xhr.send(null);
660 }
661
662 function xhrFinished(xhr) {
663 xhr.abort();
664 inFlight = remove(xhr, inFlight);
646 } 665 }
647 666
648 function rc(prefix, uri, parse, k, needsSig) { 667 function rc(prefix, uri, parse, k, needsSig) {
649 uri = cat(prefix, uri); 668 uri = cat(prefix, uri);
650 uri = flattenLocal(uri); 669 uri = flattenLocal(uri);
666 doExn(v); 685 doExn(v);
667 } 686 }
668 } else { 687 } else {
669 conn(); 688 conn();
670 } 689 }
690
691 xhrFinished(xhr);
671 } 692 }
672 }; 693 };
673 694
674 requestUri(xhr, uri, needsSig); 695 requestUri(xhr, uri, needsSig);
675 } 696 }
770 doExn(v); 791 doExn(v);
771 } 792 }
772 } 793 }
773 } 794 }
774 795
775 xhr.abort(); 796 xhrFinished(xhr);
776 797
777 connect(); 798 connect();
778 } 799 }
779 else { 800 else {
780 try { 801 try {
784 } 805 }
785 } 806 }
786 }; 807 };
787 808
788 onTimeout = function() { 809 onTimeout = function() {
789 xhr.abort(); 810 xhrFinished(xhr);
790 connect(); 811 connect();
791 }; 812 };
792 813
793 connect(); 814 connect();
794 } 815 }