@@ -12,7 +12,7 @@ const MAPSIZE = 2048 * 56
1212const KEYSIZE = 64
1313const OBJSIZE = 4056
1414
15- function logError ( x ) {
15+ function logError ( x ) {
1616 const errObj = { msg : 'unexpected datatype' , type : typeof x , value : x }
1717 console . error ( errObj )
1818 throw new Error ( JSON . stringify ( errObj ) )
@@ -24,15 +24,15 @@ const dataType = {
2424 object : x => JSON . stringify ( x ) ,
2525 number : x => logError ( x ) ,
2626 symbol : x => logError ( x ) ,
27- undefined : x => logError ( x ) ,
27+ undefined : x => logError ( x )
2828 } ,
2929 read : {
3030 string : x => JSON . parse ( x ) ,
3131 object : x => logError ( x ) ,
3232 number : x => logError ( x ) ,
3333 symbol : x => logError ( x ) ,
34- undefined : x => logError ( x ) ,
35- } ,
34+ undefined : x => logError ( x )
35+ }
3636}
3737
3838/** @typedef {import('./datasource-factory').default } DataSourceFactory */
@@ -46,15 +46,15 @@ const dataType = {
4646 */
4747const SharedMemoryMixin = superclass =>
4848 class extends superclass {
49- constructor ( map , name , namespace , options ) {
49+ constructor ( map , name , namespace , options ) {
5050 super ( map , name , namespace , options )
5151 }
5252
5353 /**
5454 * @override
5555 * @returns {import('.').Model }
5656 */
57- mapSet ( id , data ) {
57+ mapSet ( id , data ) {
5858 return this . dsMap . set ( id , dataType . write [ typeof data ] ( data ) )
5959 }
6060
@@ -64,7 +64,7 @@ const SharedMemoryMixin = superclass =>
6464 * @param {* } id
6565 * @returns {import('.').Model }
6666 */
67- mapGet ( id ) {
67+ mapGet ( id ) {
6868 if ( ! id ) {
6969 return console . warn ( { fn : this . mapGet . name , msg : 'no id provided' } )
7070 }
@@ -92,7 +92,7 @@ const SharedMemoryMixin = superclass =>
9292 * @override
9393 * @returns
9494 */
95- mapToArray ( ) {
95+ mapToArray ( ) {
9696 return this . dsMap . map ( v =>
9797 isMainThread
9898 ? JSON . parse ( v )
@@ -104,11 +104,11 @@ const SharedMemoryMixin = superclass =>
104104 * @override
105105 * @returns
106106 */
107- mapCount ( ) {
107+ mapCount ( ) {
108108 return this . dsMap . length
109109 }
110110
111- getClassName ( ) {
111+ getClassName ( ) {
112112 return this . className
113113 }
114114 }
@@ -118,7 +118,7 @@ const SharedMemoryMixin = superclass =>
118118 * @param {string } name i.e. modelName
119119 * @returns {SharedMap }
120120 */
121- function findSharedMap ( name ) {
121+ function findSharedMap ( name ) {
122122 if ( name === workerData . poolName ) return workerData . sharedMap
123123
124124 if ( workerData . dsRelated ?. length > 0 ) {
@@ -127,14 +127,14 @@ function findSharedMap(name) {
127127 }
128128}
129129
130- function rehydrateSharedMap ( name ) {
130+ function rehydrateSharedMap ( name ) {
131131 const sharedMap = findSharedMap ( name )
132132 if ( sharedMap ) return Object . setPrototypeOf ( sharedMap , SharedMap . prototype )
133133}
134134
135- function createSharedMap ( mapsize , keysize , objsize , name ) {
135+ function createSharedMap ( mapsize , keysize , objsize , name ) {
136136 return Object . assign ( new SharedMap ( mapsize , keysize , objsize ) , {
137- modelName : name , // assign modelName
137+ modelName : name // assign modelName
138138 } )
139139}
140140
@@ -146,16 +146,16 @@ function createSharedMap(mapsize, keysize, objsize, name) {
146146 * @param {import('./datasource-factory').dsOpts } options
147147 * @returns {import('./datasource').default }
148148 */
149- export function withSharedMemory (
149+ export function withSharedMemory (
150150 createDataSource ,
151151 factory ,
152152 name ,
153153 namespace ,
154154 options = { }
155155) {
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
159159
160160 try {
161161 // use thread-safe shared map
@@ -169,7 +169,7 @@ export function withSharedMemory(
169169 dsMap : sharedMap ,
170170 mixins : [ DsClass => class extends SharedMemoryMixin ( DsClass ) { } ] . concat (
171171 options . mixins || [ ]
172- ) ,
172+ )
173173 } )
174174 }
175175
0 commit comments