{"action":"created","issue":{"url":"https://api.github.com/repos/kubeless/kubeless/issues/943","repository_url":"https://api.github.com/repos/kubeless/kubeless","labels_url":"https://api.github.com/repos/kubeless/kubeless/issues/943/labels{/name}","comments_url":"https://api.github.com/repos/kubeless/kubeless/issues/943/comments","events_url":"https://api.github.com/repos/kubeless/kubeless/issues/943/events","html_url":"https://github.com/kubeless/kubeless/issues/943","id":376319482,"node_id":"MDU6SXNzdWUzNzYzMTk0ODI=","number":943,"title":"Use of singletons, global variables with nodejs","user":{"login":"brendandobbs","id":5688693,"node_id":"MDQ6VXNlcjU2ODg2OTM=","avatar_url":"https://avatars1.githubusercontent.com/u/5688693?v=4","gravatar_id":"","url":"https://api.github.com/users/brendandobbs","html_url":"https://github.com/brendandobbs","followers_url":"https://api.github.com/users/brendandobbs/followers","following_url":"https://api.github.com/users/brendandobbs/following{/other_user}","gists_url":"https://api.github.com/users/brendandobbs/gists{/gist_id}","starred_url":"https://api.github.com/users/brendandobbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendandobbs/subscriptions","organizations_url":"https://api.github.com/users/brendandobbs/orgs","repos_url":"https://api.github.com/users/brendandobbs/repos","events_url":"https://api.github.com/users/brendandobbs/events{/privacy}","received_events_url":"https://api.github.com/users/brendandobbs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-11-01T09:39:07Z","updated_at":"2018-11-09T09:17:33Z","closed_at":null,"author_association":"NONE","body":"**Is this a BUG REPORT or FEATURE REQUEST?**:\r\nFeature request\r\n\r\n**What happened**:\r\nWhen creating a function we often want to initialize an object/variable just one time when the function is first executed.\r\n\r\nIn my example I would I am creating a connection to Redis and I would like to reuse the connection as there is a significant cost to create a connection for each execution of the function. \r\n\r\n**What you expected to happen**:\r\n\r\nIf I initialize a variable/object outside of the module.exports definition I would expect that the object is initialized once, on the first execution.\r\n\r\n**How to reproduce it (as minimally and precisely as possible)**:\r\n\r\nTo test this I created a simple function that initializes a variable outside of the exported function and increments the variable inside the function. If the variable is always zero then the variable is being initialized on each execution of the function.\r\n\r\n```\r\nvar i = 0;\r\n\r\nmodule.exports = { main: async function (event, context) {\r\n    console.log(\"val = \" + i++);\r\n    return \"test\"\r\n}}\r\n```\r\n\r\nWhen I execute the function multiple times the variable 'i' is not incremented.\r\n\r\nI also tried using a global variable but I get the same result\r\n\r\n```\r\nvar global.i = 0;\r\n\r\nmodule.exports = { main: async function (event, context) {\r\n    console.log(\"val = \" + global.i++);\r\n    return \"test\"\r\n}}\r\n```\r\n\r\n**Anything else we need to know?**:\r\n\r\nI tried the same code with Azure functions and AWS Lambdas and the behaviour is different.  The variable is only initialized once on the first execution and incremented thereafter.\r\n\r\n**Environment**:\r\n- Kubernetes version (use `kubectl version`): v1.10.3\r\n- Kubeless version (use `kubeless version`): v1.0.0-alpha.8\r\n- Cloud provider or physical cluster: minikube\r\n"},"comment":{"url":"https://api.github.com/repos/kubeless/kubeless/issues/comments/437298681","html_url":"https://github.com/kubeless/kubeless/issues/943#issuecomment-437298681","issue_url":"https://api.github.com/repos/kubeless/kubeless/issues/943","id":437298681,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNzI5ODY4MQ==","user":{"login":"brendandobbs","id":5688693,"node_id":"MDQ6VXNlcjU2ODg2OTM=","avatar_url":"https://avatars1.githubusercontent.com/u/5688693?v=4","gravatar_id":"","url":"https://api.github.com/users/brendandobbs","html_url":"https://github.com/brendandobbs","followers_url":"https://api.github.com/users/brendandobbs/followers","following_url":"https://api.github.com/users/brendandobbs/following{/other_user}","gists_url":"https://api.github.com/users/brendandobbs/gists{/gist_id}","starred_url":"https://api.github.com/users/brendandobbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendandobbs/subscriptions","organizations_url":"https://api.github.com/users/brendandobbs/orgs","repos_url":"https://api.github.com/users/brendandobbs/repos","events_url":"https://api.github.com/users/brendandobbs/events{/privacy}","received_events_url":"https://api.github.com/users/brendandobbs/received_events","type":"User","site_admin":false},"created_at":"2018-11-09T09:17:33Z","updated_at":"2018-11-09T09:17:33Z","author_association":"NONE","body":"Thanks Christoph, \r\nI think you're going to meet with my colleague Johannes to discuss the options so we can park this for now.\r\n\r\nBest,\r\nBrendan"}}
{"actor":{"display_login":"brendandobbs"}}