Skip to content

Instantly share code, notes, and snippets.

@mrdoob
Created November 16, 2017 23:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrdoob/df80494a8cc53ddf8e8604a374936c31 to your computer and use it in GitHub Desktop.
Save mrdoob/df80494a8cc53ddf8e8604a374936c31 to your computer and use it in GitHub Desktop.
function JSONParseAsync( text, callback ) {
var code = 'onmessage = function ( e ) { postMessage( JSON.parse( e.data ) ); close(); }';
var blob = new Blob( [ code ], { type: 'text/plain' } );
var worker = new Worker( window.URL.createObjectURL( blob ) );
worker.addEventListener( 'message', function ( e ) { callback( e.data ); } );
worker.postMessage( text );
}
@mrdoob
Copy link
Author

mrdoob commented Nov 16, 2017

// Chrome 42+, Firefox 39+, Safari 10.1+
function JSONParseAsync( string ) {
	return ( new Response( string ) ).json(); // Returns Promise
}

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