@@ -12,7 +12,7 @@ const MAPSIZE = 2048 * 56
12
12
const KEYSIZE = 64
13
13
const OBJSIZE = 4056
14
14
15
- function logError ( x ) {
15
+ function logError ( x ) {
16
16
const errObj = { msg : 'unexpected datatype' , type : typeof x , value : x }
17
17
console . error ( errObj )
18
18
throw new Error ( JSON . stringify ( errObj ) )
@@ -24,15 +24,15 @@ const dataType = {
24
24
object : x => JSON . stringify ( x ) ,
25
25
number : x => logError ( x ) ,
26
26
symbol : x => logError ( x ) ,
27
- undefined : x => logError ( x ) ,
27
+ undefined : x => logError ( x )
28
28
} ,
29
29
read : {
30
30
string : x => JSON . parse ( x ) ,
31
31
object : x => logError ( x ) ,
32
32
number : x => logError ( x ) ,
33
33
symbol : x => logError ( x ) ,
34
- undefined : x => logError ( x ) ,
35
- } ,
34
+ undefined : x => logError ( x )
35
+ }
36
36
}
37
37
38
38
/** @typedef {import('./datasource-factory').default } DataSourceFactory */
@@ -46,15 +46,15 @@ const dataType = {
46
46
*/
47
47
const SharedMemoryMixin = superclass =>
48
48
class extends superclass {
49
- constructor ( map , name , namespace , options ) {
49
+ constructor ( map , name , namespace , options ) {
50
50
super ( map , name , namespace , options )
51
51
}
52
52
53
53
/**
54
54
* @override
55
55
* @returns {import('.').Model }
56
56
*/
57
- mapSet ( id , data ) {
57
+ mapSet ( id , data ) {
58
58
return this . dsMap . set ( id , dataType . write [ typeof data ] ( data ) )
59
59
}
60
60
@@ -64,7 +64,7 @@ const SharedMemoryMixin = superclass =>
64
64
* @param {* } id
65
65
* @returns {import('.').Model }
66
66
*/
67
- mapGet ( id ) {
67
+ mapGet ( id ) {
68
68
if ( ! id ) {
69
69
return console . warn ( { fn : this . mapGet . name , msg : 'no id provided' } )
70
70
}
@@ -92,7 +92,7 @@ const SharedMemoryMixin = superclass =>
92
92
* @override
93
93
* @returns
94
94
*/
95
- mapToArray ( ) {
95
+ mapToArray ( ) {
96
96
return this . dsMap . map ( v =>
97
97
isMainThread
98
98
? JSON . parse ( v )
@@ -104,11 +104,11 @@ const SharedMemoryMixin = superclass =>
104
104
* @override
105
105
* @returns
106
106
*/
107
- mapCount ( ) {
107
+ mapCount ( ) {
108
108
return this . dsMap . length
109
109
}
110
110
111
- getClassName ( ) {
111
+ getClassName ( ) {
112
112
return this . className
113
113
}
114
114
}
@@ -118,7 +118,7 @@ const SharedMemoryMixin = superclass =>
118
118
* @param {string } name i.e. modelName
119
119
* @returns {SharedMap }
120
120
*/
121
- function findSharedMap ( name ) {
121
+ function findSharedMap ( name ) {
122
122
if ( name === workerData . poolName ) return workerData . sharedMap
123
123
124
124
if ( workerData . dsRelated ?. length > 0 ) {
@@ -127,14 +127,14 @@ function findSharedMap(name) {
127
127
}
128
128
}
129
129
130
- function rehydrateSharedMap ( name ) {
130
+ function rehydrateSharedMap ( name ) {
131
131
const sharedMap = findSharedMap ( name )
132
132
if ( sharedMap ) return Object . setPrototypeOf ( sharedMap , SharedMap . prototype )
133
133
}
134
134
135
- function createSharedMap ( mapsize , keysize , objsize , name ) {
135
+ function createSharedMap ( mapsize , keysize , objsize , name ) {
136
136
return Object . assign ( new SharedMap ( mapsize , keysize , objsize ) , {
137
- modelName : name , // assign modelName
137
+ modelName : name // assign modelName
138
138
} )
139
139
}
140
140
@@ -146,16 +146,16 @@ function createSharedMap(mapsize, keysize, objsize, name) {
146
146
* @param {import('./datasource-factory').dsOpts } options
147
147
* @returns {import('./datasource').default }
148
148
*/
149
- export function withSharedMemory (
149
+ export function withSharedMemory (
150
150
createDataSource ,
151
151
factory ,
152
152
name ,
153
153
namespace ,
154
154
options = { }
155
155
) {
156
- const mapsize = options . mapsize || MAPSIZE
157
- const keysize = options . keysize || KEYSIZE
158
- const objsize = options . objsize || OBJSIZE
156
+ const mapsize = options . mapsize || process . env . MAPSIZE || MAPSIZE
157
+ const keysize = options . keysize || process . env . KEYSIZE || KEYSIZE
158
+ const objsize = options . objsize || process . env . OBJSIZE || OBJSIZE
159
159
160
160
try {
161
161
// use thread-safe shared map
@@ -169,7 +169,7 @@ export function withSharedMemory(
169
169
dsMap : sharedMap ,
170
170
mixins : [ DsClass => class extends SharedMemoryMixin ( DsClass ) { } ] . concat (
171
171
options . mixins || [ ]
172
- ) ,
172
+ )
173
173
} )
174
174
}
175
175
0 commit comments