-
Notifications
You must be signed in to change notification settings - Fork 13
/
docs.js
281 lines (228 loc) · 16.8 KB
/
docs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/**
Creates an object which uses an
{@link https://lmax-exchange.github.io/disruptor/|LMAX Disruptor}
to store data in shared memory.
@param {string} shm_name - Name of shared memory object to use (see {@link http://pubs.opengroup.org/onlinepubs/009695399/functions/shm_open.html|shm_open}).
@param {integer} num_elements - Number of elements in the Disruptor (i.e. its capacity).
@param {integer} element_size - Size of each element in bytes.
@param {integer} num_consumers - Total number of objects that will be reading data from the Disruptor.
@param {integer} consumer - Each object that reads data from the Disruptor must have a unique ID. This should be a number between 0 and `num_consumers - 1`. If the object is only going to write data, `consumer` can be anything.
@param {boolean} init - Whether to create and initialize the shared memory backing the Disruptor. You should arrange your application so this is done once, at the start.
@param {boolean} spin - If `true` then methods on this object which read from the Disruptor won't return to your application until a value is ready. Methods which write to the Disruptor won't return while the Disruptor is full. The `*Sync` methods will block Node's main thread and the asynchronous methods will repeatedly post tasks to the thread pool, in order to let other tasks get a look in. If you want to implement your own retry algorithm (or use some out-of-band notification mechanism), specify `spin` as `false` and check method return values.
*/
class Disruptor
{
constructor(shm_name, num_elements, element_size, num_consumers, consumer, init, spin)
{
}
/**
Reserve the next element in the Disruptor for writing data into.
@param {produceClaimCallback} [cb] - Called once an element has been reserved, or `spin` (see the {@link Disruptor|constructor}) is `false` and the Disruptor is full. If you don't pass `cb` then a `Promise`.
@returns {undefined | Promise} - If `cb` is _not_ supplied then a `Promise` is returned which resolves to the data that would have been passed to it.
*/
produceClaim(cb)
{
}
/**
Reserve the next element in the Disruptor for writing data into.
@returns {Buffer} - Buffer for writing data to the Disruptor. If the Disruptor was full and `spin` (see the {@link Disruptor|constructor}) is `false`, the buffer will be empty. Otherwise its length will be `element_size`. The buffer is backed by shared memory so may be overwitten after you call {@link Disruptor#produceCommit|produceCommit} or {@link Disruptor#produceCommitSync|produceCommitSync}.
*/
produceClaimSync()
{
}
/**
Reserve a number of elements in the Disruptor for writing data into.
@param {integer} n - Number of elements to reserve.
@param {produceClaimManyCallback} [cb] - Called once the elements have been reserved, or `spin` (see the {@link Disruptor|constructor}) is `false` and the Disruptor didn't have enough free elements.
@returns {undefined | Promise} - If `cb` is _not_ supplied then a `Promise` is returned which resolves to the data that would have been passed to it.
*/
produceClaimMany(n, cb)
{
}
/**
Reserve a number of elements in the Disruptor for writing data into.
@param {integer} n - Number of elements to reserve.
@returns {Buffer[]} - Array of buffers for writing data to the Disruptor. If the Disruptor didn't have enough free elements and `spin` (see the {@link Disruptor|constructor}) is `false`, the array will be empty. Otherwise, it will contain at least one buffer and each buffer will be a multiple of `element_size` in length. The total size of the buffers in the array will be `n * element_size`. The buffers are backed by shared memory so may be overwritten after you call {@link Disruptor#produceCommit|produceCommit} or {@link Disruptor#produceCommitSync|produceCommitSync}.
*/
produceClaimManySync(n)
{
}
/**
Reserve all free elements in the Disruptor for writing data into.
@param {integer} max - Maximum number of free elements to reserve.
@param {produceClaimManyCallback} [cb] - Called once elements have been reserved, or `spin` (see the {@link Disruptor|constructor}) is `false` and the Disruptor didn't have any free elements.
@returns {undefined | Promise} - If `cb` is _not_ supplied then a `Promise` is returned which resolves to the data that would have been passed to it.
*/
produceClaimAvail(max, cb)
{
}
/**
Reserve all free elements in the Disruptor for writing data into.
@param {integer} max - Maximum number of free elements to reserve.
@returns {Buffer[]} - Array of buffers for writing data to the Disruptor. If the Disruptor didn't have any free elements and `spin` (see the {@link Disruptor|constructor}) is `false`, the array will be empty. Otherwise, it will contain at least one buffer and each buffer will be a multiple of `element_size` is length. The buffers are backed by shared memory so may be overwritten after you call {@link Disruptor#produceCommit|produceCommit} or {@link Disruptor#produceCommitSync|produceCommitSync}.
*/
produceClaimAvailSync(max)
{
}
/**
Commit data to the Disruptor. Call this once you've finished writing data
to buffers you reserved.
@param {integer} [claimStart] - Specifies the start of the buffer you want to commit. You can pass a value you received via {@link produceClaimCallback}, {@link produceClaimManyCallback} or {@link produceClaimAvailCallback}. If you don't specify a value, {@link Disruptor#prevClaimStart|prevClaimStart} is used.
@param {integer} [claimEnd] - Specifies the end of the buffer you want to commit. You can pass a value you received via {@link produceClaimCallback}, {@link produceClaimManyCallback} or {@link produceClaimAvailCallback}. If you don't specify a value, {@link Disruptor#prevClaimEnd|prevClaimEnd} is used.
@param {produceCommitCallback} [cb] - Called once the elements in the buffers have been committed to the Disruptor, or `spin` (see the {@link Disruptor|constructor}) is `false` and the elements couldn't be committed (because other producers haven't committed their data yet). No copying occurs during the operation.
@returns {undefined | Promise} - If `cb` is _not_ supplied then a `Promise` is returned which resolves to the data that would have been passed to it.
*/
produceCommit(claimStart, claimEnd, cb)
{
}
/**
Commit data to the Disruptor. Call this once you've finished writing data
to buffers you reserved.
@param {integer} [claimStart] - Specifies the start of the buffer you want to commit. You can pass a value you received via {@link produceClaimCallback}, {@link produceClaimManyCallback} or {@link produceClaimAvailCallback}. If you don't specify a value, {@link Disruptor#prevClaimStart|prevClaimStart} is used.
@param {integer} [claimEnd] - Specifies the end of the buffer you want to commit. You can pass a value you received via {@link produceClaimCallback}, {@link produceClaimManyCallback} or {@link produceClaimAvailCallback}. If you don't specify a value, {@link Disruptor#prevClaimEnd|prevClaimEnd} is used.
@returns {boolean} - Whether the data was committed to the Disruptor. If some elements reserved before `claimStart` remain uncommitted and `spin` (see the {@link Disruptor|constructor}) is `false`, the return value will be `false`. Otherwise the data was committed and the return value will be `true`.
*/
produceCommitSync(claimStart, claimEnd)
{
}
/**
Read new data from the Disruptor.
Elements written to since {@link Disruptor#consumeNew|consumeNew}, {@link Disruptor#consumeNewSync|consumeNewSync} or
{@link Disruptor#consumeCommit|consumeCommit} were called on this object are passed to `cb`.
A call to {@link Disruptor#consumeCommit|consumeCommit} is made before checking for new data.
@param {consumeNewCallback} [cb] - Called once new elements are ready, or `spin` (see the {@link Disruptor|constructor}) is `false` and no elements have been written to the Disruptor.
@returns {undefined | Promise} - If `cb` is _not_ supplied then a `Promise` is returned which resolves to the data that would have been passed to it.
*/
consumeNew(cb)
{
}
/**
Read new data from the Disruptor.
Elements written to since {@link Disruptor#consumeNew|consumeNew}, {@link Disruptor#consumeNewSync|consumeNewSync} or
{@link Disruptor#consumeCommit|consumeCommit} were called on this object are returned.
A call to {@link Disruptor#consumeCommit|consumeCommit} is made before checking for new data.
@returns {Buffer[]} - Array of buffers containing new data ready to read from the Disruptor. If no new data was available and `spin` (see the {@link Disruptor|constructor}) is `false`, the array will be empty. Otherwise it will contain at least one buffer and each buffer will be a multiple of `element_size` in length. The buffers are backed by shared memory so may be overwritten after you call {@link Disruptor#consumeCommit|consumeCommit}.
*/
consumeNewSync()
{
}
/**
Tell the Disruptor you've finished reading data. Call this once you've
finished with buffers returned by {@link Disruptor#consumeNew|consumeNew} or
{@link Disruptor#consumeNewSync|consumeNewSync}.
This is called by {@link Disruptor#consumeNew|consumeNew} and {@link Disruptor#consumeNewSync|consumeNewSync} before
they check for new data.
@return {boolean} - Whether the Disruptor was in the expected state. This will always return `true` unless your application incorrectly uses objects with the same consumer ID to access the Disruptor concurrently.
*/
consumeCommit()
{
}
/**
Reserve elements you've reserved before.
@param {integer} claimStart - Specifies the start of the buffer you want to reserve. You can pass a value you received via {@link produceClaimCallback}, {@link produceClaimManyCallback}, {@link produceClaimAvailCallback} or {@link Disruptor#prevClaimStart|prevClaimStart}.
@param {integer} claimEnd - Specifies the end of the buffer you want to reserve. You can pass a value you received via {@link produceClaimCallback}, {@link produceClaimManyCallback}, {@link produceClaimAvailCallback} or {@link Disruptor#prevClaimEnd|prevClaimEnd}.
*/
produceRecover(claimStart, claimEnd)
{
}
/**
Detaches from the shared memory backing the Disruptor.
Although this will be called when the object is garbage collected,
you can force the shared memory to be unmapped by calling this function.
Don't use the object again afterwards!
@param {boolean} [mark_ignore=false] - Whether publishers should ignore consumers that have this Disruptor's unique ID.
*/
release()
{
}
/**
@returns {integer} - The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced _before_ the previous call to {@link Disruptor#produceClaim|produceClaim}, {@link Disruptor#produceClaimSync|produceClaimSync}, {@link Disruptor#produceClaimMany|produceClaimMany}, {@link Disruptor#produceClaimManySync|produceClaimManySync}, {@link Disruptor#produceClaimAvail|produceClaimAvail} or {@link Disruptor#produceClaimAvailSync|produceClaimAvailSync}.
*/
get prevClaimStart()
{
}
/**
@returns {integer} - The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced _after_ the previous call to {@link Disruptor#produceClaim|produceClaim}, {@link Disruptor#produceClaimSync|produceClaimSync}, {@link Disruptor#produceClaimMany|produceClaimMany}, {@link Disruptor#produceClaimManySync|produceClaimManySync}, {@link Disruptor#produceClaimAvail|produceClaimAvail} or {@link Disruptor#produceClaimAvailSync|produceClaimAvailSync}, minus 1.
*/
get prevClaimEnd()
{
}
/**
@returns {integer} - The Disruptor maintains a strictly increasing count of the total number of elements consumed since it was created. This is the how many elements were consumed _before_ the previous call to {@link Disruptor#consumeNew|consumeNew} or {@link Disruptor#consumeNewSync|consumeNewSync}.
*/
get prevConsumeStart()
{
}
/**
@returns {integer} - Size of each element in the Disruptor in bytes.
*/
get elementSize()
{
}
/**
@returns {boolean} - Whether methods on this object which read from the Disruptor won't return to your application until a value is ready.
*/
get spin()
{
}
}
/**
Callback type for reserving a single element in the Disruptor for writing.
@param {?Error} err - Error, if one occurred.
@param {Buffer} buf - Buffer for writing data to the Disruptor. If the Disruptor was full and `spin` (see the {@link Disruptor|constructor}) is `false`, `buf` will be empty. Otherwise its length will be `element_size`. `buf` is backed by shared memory so may be overwritten after you call {@link Disruptor#produceCommit|produceCommit} or {@link Disruptor#produceCommitSync|produceCommitSync}.
@param {integer} claimStart - The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced before `buf` was reserved.
@param {integer} claimEnd - The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced after `buf` was reserved, minus 1.
*/
function produceClaimCallback(err, buf, claimStart, claimEnd)
{
}
/**
Callback type for reserving a number of elements in the Disruptor for writing.
@param {?Error} err - Error, if one occurred.
@param {Buffer[]} bufs - Array of buffers for writing data to the Disruptor. If the Disruptor didn't have enought free elements and `spin` (see the {@link Disruptor|constructor}) is `false`, `bufs` will be empty. Otherwise, it will contain at least one buffer and each buffer will be a multiple of `element_size` in length. The maximum length of all buffers will be `element_size * num_elements` bytes. The buffers are backed by shared memory so may be overwritten after you call {@link Disruptor#produceCommit|produceCommit} or {@link Disruptor#produceCommitSync|produceCommitSync}.
@param {integer} claimStart - The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced before `bufs` was reserved.
@param {integer} claimEnd - The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced after `bufs` was reserved, minus 1.
*/
function produceClaimManyCallback(err, bufs, claimStart, claimEnd)
{
}
/**
Callback type for commiting data to the Disruptor
@param {?Error} err - Error, if one occurred.
@param {boolean} committed - Whether the data was committed to the Disruptor. If some elements reserved before `claimStart` remain uncommitted and `spin` (see the {@link Disruptor|constructor}) is `false`, `committed` will be `false`. Otherwise the data was committed and `committed` will be `true`.
*/
function produceCommitCallback(err, committed)
{
}
/**
Callback type for reading new data from the Disruptor
@param {?Error} err - Error, if one occurred.
@param {Buffer[]} bufs - Array of buffers containing new data ready to read from the Disruptor. If no new data was available and `spin` (see the {@link Disruptor|constructor}) is `false`, the array will be empty. Otherwise it will contain at least one buffer and each buffer will be a multiple of `element_size` in length. The buffers are backed by shared memory so may be overwritten after you call {@link Disruptor#consumeCommit|consumeCommit}.
@param {integer} start - The Disruptor maintains a strictly increasing count of the total number of elements consumed since it was created. This is how many elements were consumed before `bufs` was read (if `bufs` isn't empty).
*/
function consumeNewCallback(err, bufs, start)
{
}
const stream = require('stream');
/**
Creates a stream which reads from a disruptor.
@param {Disruptor} disruptor - {@link Disruptor} to read from. Its `element_size` must be 1 byte and it must not `spin`.
@param {Object} options - Passed to {@link stream.Readable}.
*/
class DisruptorReadStream extends stream.Readable
{
constructor(disruptor, options)
{
}
}
/**
Creates a stream which writes to a disruptor.
@param {Disruptor} disruptor - {@link Distruptor} to write to. Its `element_size` must be 1 byte and it must not `spin`.
@param {Object} options - Passed to {@link stream.Writable}.
*/
class DisruptorWriteStream extends stream.Writable
{
constructor(disruptor, options)
{
}
}