Skip to content

XMLHttpRequest: non-standard unref() and ref(), like a Node.js socket - #525

Draft
wesgarland wants to merge 1 commit into
mainfrom
wes/feat/xhr-unref
Draft

wesgarland wants to merge 1 commit into
mainfrom
wes/feat/xhr-unref

Conversation

@wesgarland

Copy link
Copy Markdown
Collaborator

Adds non-standard XMLHttpRequest.prototype.unref() and ref(), matching what a Node.js socket offers. A request sent after unref() runs as an asyncio task that pm.wait() does not count, so it does not keep the program running; ref() undoes it. Errors still reach the XHR's error handling.

dcp-client needs this: under Node.js, engine.io-client's autoUnref option unrefs its long-poll sockets (through xmlhttprequest-ssl), but under PythonMonkey it uses the global XMLHttpRequest, so an open dcp connection's long-poll keeps pmjs running forever.

tests/js/xhr-unref.bash (a server that answers after 5 s): an unref()'d request is not waited for, a ref()'d one is. Fails on 1.5.1 (xhr.unref is not a function); passes with this change overlaid on the 1.5.1 wheel, as does tests/python/test_xhr.py.

A request sent after unref() runs as an asyncio task that pm.wait() does not count, so a pending
request (e.g. a long-poll) does not keep the program running; ref() undoes it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant