You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Longer execution periods reduce the number of total data requests, but also reduce the responsiveness of the
60
+
`load` futures.
61
+
62
+
If desired, you can manually execute the `batchLoadFunction` and complete the futures at any time, using the
63
+
`.execute()` method.
64
+
65
+
Scheduled execution can be disabled by setting `executionPeriod` to `nil`, but be careful - you *must* call `.execute()`
66
+
manually in this case. Otherwise, the futures will never complete.
67
+
46
68
#### Disable batching
47
-
It is possible to disable batching `DataLoaderOptions(batchingEnabled: false)`
48
-
It will invoke `batchLoadFunction` immediately whenever any key is loaded
69
+
It is possible to disable batching by setting the `batchingEnabled` option to `false`
70
+
It will invoke the `batchLoadFunction` immediately when a key is loaded.
71
+
49
72
50
73
### Caching
51
74
52
-
DataLoader provides a memoization cache for all loads which occur in a single
53
-
request to your application. After `.load()` is called once with a given key,
54
-
the resulting value is cached to eliminate redundant loads.
75
+
DataLoader provides a memoization cache. After `.load()` is called with a key, the resulting value is cached
76
+
for the lifetime of the DataLoader object. This eliminates redundant loads.
55
77
56
-
In addition to relieving pressure on your data storage, caching results per-request
57
-
also creates fewer objects which may relieve memory pressure on your application:
78
+
In addition to relieving pressure on your data storage, caching results also creates fewer objects which may
79
+
relieve memory pressure on your application:
58
80
59
81
```swift
60
82
let userLoader = DataLoader<Int, Int>(...)
@@ -164,16 +186,20 @@ let myLoader = DataLoader<String, String>(batchLoadFunction: { keys in
164
186
165
187
## Contributing 🤘
166
188
167
-
All your feedback and help to improve this project is very welcome. Please create issues for your bugs, ideas and enhancement requests, or better yet, contribute directly by creating a PR. 😎
189
+
All your feedback and help to improve this project is very welcome. Please create issues for your bugs, ideas and
190
+
enhancement requests, or better yet, contribute directly by creating a PR. 😎
168
191
169
-
When reporting an issue, please add a detailed instruction, and if possible a code snippet or test that can be used as a reproducer of your problem. 💥
192
+
When reporting an issue, please add a detailed instruction, and if possible a code snippet or test that can be used
193
+
as a reproducer of your problem. 💥
170
194
171
-
When creating a pull request, please adhere to the current coding style where possible, and create tests with your code so it keeps providing an awesome test coverage level 💪
195
+
When creating a pull request, please adhere to the current coding style where possible, and create tests with your
196
+
code so it keeps providing an awesome test coverage level 💪
172
197
173
198
## Acknowledgements 👏
174
199
175
-
This library is entirely a Swift version of Facebooks [DataLoader](https://github.com/facebook/dataloader). Developed by [Lee Byron](https://github.com/leebyron) and
176
-
[Nicholas Schrock](https://github.com/schrockn) from [Facebook](https://www.facebook.com/).
200
+
This library is entirely a Swift version of Facebooks [DataLoader](https://github.com/facebook/dataloader).
201
+
Developed by [Lee Byron](https://github.com/leebyron) and [Nicholas Schrock](https://github.com/schrockn)
letidentityLoader=DataLoader<Int,Int>(options:DataLoaderOptions()){ keys in
32
+
letidentityLoader=DataLoader<Int,Int>(){ keys in
33
33
eventLoopGroup.next().makeSucceededFuture([])
34
34
}
35
35
36
36
letvalue=try identityLoader.load(key:1, on: eventLoopGroup)
37
37
38
-
XCTAssertNoThrow(try identityLoader.execute())
39
-
40
38
XCTAssertThrowsError(try value.wait(),"The function did not return an array of the same length as the array of keys. \nKeys count: 1\nValues count: 0")
41
39
}
42
40
@@ -46,7 +44,7 @@ class DataLoaderAbuseTests: XCTestCase {
0 commit comments