json-emitter 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -0
- data/lib/json-emitter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2228e23ca76886db68f546e171db2e9c318f35c02e4262b19adf162d43e1151
|
4
|
+
data.tar.gz: c137299a78e76f0ffdeba789d9477ef94a4b161d0718287ba074dcbc90f4c82d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2a21066822a1e4f84df8facee734dd60951dbd489d5e80444be11546e9851e77f9d8c9edc6f9fd1900fd55407cf96cbc193c4402223aa78459265a119ab75a5
|
7
|
+
data.tar.gz: 2b025e42af1069efc578d5138e6535b35b507659e931ce59dd9164d96adc7dd1d1ceec334b22aa710a233198b63d8cad033b67e244d52a78854d553383e41bea
|
data/README.md
CHANGED
@@ -98,6 +98,37 @@ File.open("~/out.json", "w+") { |f|
|
|
98
98
|
}
|
99
99
|
```
|
100
100
|
|
101
|
+
# Deailing with errors
|
102
|
+
|
103
|
+
When streaming an HTTP response, you can't change the response code once you start sending data. So if you hit an error after you start, you need another way to communicate errors to the client.
|
104
|
+
|
105
|
+
One way is to always steam an object that includes an `errors` field. Any errors will be collected while the `Enumerator` is running. After it's finished, they'll be added to the JSON object.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
def get_data
|
109
|
+
errors = []
|
110
|
+
enum = Enumerator.new { |y|
|
111
|
+
finished = false
|
112
|
+
until finished
|
113
|
+
data, errs, finished = get_data_chunk
|
114
|
+
if errs
|
115
|
+
errors += errs
|
116
|
+
finished = true
|
117
|
+
next
|
118
|
+
end
|
119
|
+
data.each { x| y << x }
|
120
|
+
end
|
121
|
+
}
|
122
|
+
return enum, -> { errors }
|
123
|
+
end
|
124
|
+
|
125
|
+
items_enum, errors_proc = get_data
|
126
|
+
JsonEmitter.object({
|
127
|
+
items: items_enum,
|
128
|
+
errors: errors_proc,
|
129
|
+
})
|
130
|
+
```
|
131
|
+
|
101
132
|
# License
|
102
133
|
|
103
134
|
MIT License. See LICENSE for details.
|
data/lib/json-emitter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-emitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
|
-
rubygems_version: 3.0.3
|
59
|
+
rubygems_version: 3.0.3.1
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: Efficiently generate tons of JSON
|