Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async stringify (serialize) to JSON in javascript

In my react-native app I need to stringify (serialize) big objects and not to block js thread - asynchronous api that uses another threads, something like this:

JSON.stringifyAsync({ foo: "bar" }).then(x => console.log(x));

Please don't suggest to wrap JSON.stringify into Promise, it just defers blocking of js thread.

like image 429
Alexander Danilov Avatar asked Nov 01 '16 20:11

Alexander Danilov


1 Answers

I don't think this is currently possible. It's an issue for node.js (see here, here, and here) and I don't think the situation is any better for browsers or other JS engines.

There is an EcmaScript proposal (see here) to add functions JSON.parseAsync and JSON.stringifyAsync methods. I don't know the status of this proposal. From the proposal: "There is no way of transpilating the actual effect of this proposal." So it looks like the proposer(s) agree that there's currently no way to do this.

like image 156
Ted Hopp Avatar answered Oct 16 '22 21:10

Ted Hopp