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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With