admin管理员组文章数量:1023738
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.
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.
Share Improve this question edited Jun 15, 2022 at 10:46 gentlee asked Nov 1, 2016 at 20:49 gentleegentlee 3,7251 gold badge33 silver badges47 bronze badges 6- 4 So the first choice didn't work. What streaming JSON parser have you tested and what problems did you find there? Do you have any information on what you've already done? – ssube Commented Nov 1, 2016 at 20:54
- I don't need streaming json parser, i need just true async one. If you have an answer pls just give it. And whats the reason of your downvote? – gentlee Commented Nov 1, 2016 at 21:01
- 1 @ssube - How would a streaming parser help with OP's problem? – Ted Hopp Commented Nov 1, 2016 at 21:19
- I'm pretty sure that streaming parser would help, because by its nature it's async, hence non-blocking, for example this one should do the job: npmjs./package/json-stream-stringify – Maxim Mazurok Commented Jun 10, 2022 at 2:36
- @MaximMazurok if it is 100% JS then it can't be non-blocking. – gentlee Commented Jun 14, 2022 at 10:39
2 Answers
Reset to default 7I 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.
Maybe you can split the objects and merge the processed parts at the end.
Or do something like this:
async.eachOf(obj,function(value,key,callback){
async.setImmediate(function(){
// do something
});
}, function(err,reply){
});
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.
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.
Share Improve this question edited Jun 15, 2022 at 10:46 gentlee asked Nov 1, 2016 at 20:49 gentleegentlee 3,7251 gold badge33 silver badges47 bronze badges 6- 4 So the first choice didn't work. What streaming JSON parser have you tested and what problems did you find there? Do you have any information on what you've already done? – ssube Commented Nov 1, 2016 at 20:54
- I don't need streaming json parser, i need just true async one. If you have an answer pls just give it. And whats the reason of your downvote? – gentlee Commented Nov 1, 2016 at 21:01
- 1 @ssube - How would a streaming parser help with OP's problem? – Ted Hopp Commented Nov 1, 2016 at 21:19
- I'm pretty sure that streaming parser would help, because by its nature it's async, hence non-blocking, for example this one should do the job: npmjs./package/json-stream-stringify – Maxim Mazurok Commented Jun 10, 2022 at 2:36
- @MaximMazurok if it is 100% JS then it can't be non-blocking. – gentlee Commented Jun 14, 2022 at 10:39
2 Answers
Reset to default 7I 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.
Maybe you can split the objects and merge the processed parts at the end.
Or do something like this:
async.eachOf(obj,function(value,key,callback){
async.setImmediate(function(){
// do something
});
}, function(err,reply){
});
本文标签: Parallel stringify (serialize) to JSON in javascriptStack Overflow
版权声明:本文标题:Parallel stringify (serialize) to JSON in javascript - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745604625a2158657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论