function initBuffer(obj){ let buffer = { data: undefined, offset: 0, allocSize: 256 }; // try to predict object size to reduce number of allocations extendBufferIfNeeded(buffer, sizeof(obj)); return buffer; }
async function handleNewMessageFromInstance(instance, messageParam) { logger.debug(`New message from instance ${instance.id}`); statsService.track('MESSAGE_TO_USER', { instance_id: instance.id, message_size: sizeof(messageParam), sent_at: messageParam.sent_at, received_at: new Date().getTime(), }); const message = messageParam; // adding sending instance_id message.instance_id = instance.id; const roomName = `user:${message.user_id}`; io.to(roomName).emit('message', message); }
/** * Sets a result value to the lru cache, this value is associated with the {@link Action.id} * * @param {string} key - id associated with the value * @param {*} value - value that should be store by the cache */ set(key, value){ assert(TypeCheck.isString(key), 'Invalid action key!'); if (this[_cache] === null){ this[_cache] = new LruCacheBase({ max: this[_size], maxAge: this[_lifespan], length: (n, k) => { return n.memorySize; }, }); } const resultHolder = {}; resultHolder.memorySize = sizeof(value); resultHolder.data = value; this[_cache].set(key, resultHolder); }
else Store = JSON.parse(JSON.stringify(rawExtensionDocument.store)); Store[key] = value; if (sizeof(Store) > 25000) { throw new GABError("STORAGE_SIZE_MAX"); } else {
async function handleNewMessageFromInstance(instance, messageParam) { logger.debug(`New message from instance ${instance.id}`); statsService.track('MESSAGE_TO_USER', { instance_id: instance.id, message_size: sizeof(messageParam), sent_at: messageParam.sent_at, received_at: new Date().getTime(), }); const message = messageParam; // adding sending instance_id message.instance_id = instance.id; const roomName = `user:${message.user_id}`; io.to(roomName).emit('message', message); }