{"id":15625452,"url":"https://github.com/daniel15/jspool","last_synced_at":"2025-07-07T05:34:37.499Z","repository":{"id":23874745,"uuid":"27253588","full_name":"Daniel15/JSPool","owner":"Daniel15","description":"Pooling of reusable JavaScript engines for fast, performant scripting integration in in .NET applications","archived":false,"fork":false,"pushed_at":"2019-01-05T07:05:54.000Z","size":139,"stargazers_count":36,"open_issues_count":5,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-28T15:52:10.118Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Daniel15.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-28T05:53:39.000Z","updated_at":"2025-01-21T05:57:11.000Z","dependencies_parsed_at":"2022-08-22T06:30:34.530Z","dependency_job_id":null,"html_url":"https://github.com/Daniel15/JSPool","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/Daniel15/JSPool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel15%2FJSPool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel15%2FJSPool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel15%2FJSPool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel15%2FJSPool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Daniel15","download_url":"https://codeload.github.com/Daniel15/JSPool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel15%2FJSPool/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262981631,"owners_count":23394563,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T10:01:45.605Z","updated_at":"2025-07-07T05:34:37.479Z","avatar_url":"https://github.com/Daniel15.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"JSPool\n======\n\nJSPool facilitates easy integration of JavaScript scripting into a .NET \napplication in a scalable and performant manner. It does so by creating a pool\nof engines that can be reused multiple times. This makes it easy to use \nJavaScript libraries that have long initialisation times without having to \ncreate a new engine and load the script again every time.\n\nIt is powered by the [JavaScriptEngineSwitcher](https://github.com/Taritsyn/JavaScriptEngineSwitcher)\nlibrary.\n\nFeatures\n========\n - Supports any JavaScript engine supported by JavaScriptEngineSwitcher \n   (including V8, MSIE, Jint, and Jurassic).\n - Pools are thread-safe.\n - Automatically calls an initialisation callback when engines are created. This\n   can be used to load JavaScript libraries.\n - Pools have a configurable number of maximum engines.\n - There is no global state; pools are instantiated so you can have multiple \n   pools in your application, each with their own configuration.\n\nUsage\n=====\n\nInstallation can be done either through NuGet (`Install-Package JSPool`) or by \ncloning the Git repository and running `dev-build.bat`. In addition to JSPool, \nyou will need to have at least one engine supported by JavaScriptEngineSwitcher\ninstalled (eg. [V8](https://www.nuget.org/packages/JavaScriptEngineSwitcher.V8) \nor [MSIE](http://www.nuget.org/packages/JavaScriptEngineSwitcher.Msie)). V8 is\nrecommended.\n\n```csharp\nvar pool = new JsPool(new JsPoolConfig\n{\n  Initializer = initEngine =\u003e\n  {\n    // This initializer will be called whenever a new engine is created. In a \n    // real app you'd commonly use ExecuteFile and ExecuteResource to load\n    // libraries into the engine.\n    initEngine.Execute(@\"\n      function sayHello(name) {\n        return 'Hello ' + name + '!';\n      }\n    \");\n  }\n});\n\n// Get an engine from the pool. The engine will be returned to the pool when\n// disposed. In this case, the using() block will automatically return the\n// engine to the pool when it falls out of scope.\nusing (var engine = pool.GetEngine()) {\n  var message = engine.CallFunction\u003cstring\u003e(\"sayHello\", \"Daniel\");\n  Console.WriteLine(message); // \"Hello Daniel!\"\n}\n\n// Disposing the pool will also dispose all its engines. Always dispose the pool\n// when it is no longer required.\npool.Dispose();\n```\n\nConfiguration\n=============\n\nThe following configuration settings are available for JSPool:\n\n - **StartEngines**: Number of engines to initially start when a pool is \n   created. Defaults to 10.\n - **MaxEngines**: Maximum number of engines that will be created in the pool. \n   If an engine is requested but all the current engines are busy, a new engine \n   will be created unless the maximum has been reached. Defaults to 25.\n - **Initializer**: Action called when a new engine is created. This should \n   configure the environment and load any required JavaScript libraries. The \n   engine will not be available for use until this method has completed.\n - **MaxUsagesPerEngine**: The maximum number of times an engine can be reused\n   before it is disposed. 0 is unlimited. Defaults to 100.\n - **GarbageCollectionInterval**: The number of times an engine can be reused\n   before its garbage collector is ran. Only affects engines that support \n   garbage collection (V8). Defaults to 20.\n - **GetEngineTimeout**: If all engines in the pool are currently busy and \n   *MaxEngines* has been reached, the call to `GetEngine` will block for this \n   period of time waiting for an engine to become free. If an engine can not be \n   acquired in this timeframe, throws a `JsPoolExhaustedException`. Set this to\n   -1 to wait indefinitely. Defaults to 5 seconds.\n - **WatchPath**: Path to watch for file changes. If any files in this path\n   change, all engines in the pool will be recycled.\n - **WatchFiles**: Used in combination with WatchPath. If specified, only these\n   particular files within the path will be watched. If not specified, all files\n   within the path will be watched.\n - **EngineFactory**: Method used to create new JavaScript engines. Defaults to \n   the default factory method in JavaScriptEngineSwitcher\n   (`JsEngineSwitcher.Current.CreateDefaultJsEngineInstance`)\n\n\nChangelog\n=========\n4.0 - 4th January 2019\n----------------------\n - Updated to JavaScriptEngineSwitcher 3.0. Upgrade instructions can be found in the [How to upgrade applications to version 3.X](https://github.com/Taritsyn/JavaScriptEngineSwitcher/wiki/How-to-upgrade-applications-to-version-3.X) document. \n - [#37](https://github.com/Daniel15/JSPool/pull/37) - Fix JsPool recycling problem in a concurrent environment. Thanks @benokit\n - [#34](https://github.com/Daniel15/JSPool/pull/34) - Made properties of the `PooledJsEngine` class virtual, to ease unit testing. Thanks @Taritsyn\n\n4.0-beta1 - 30th June 2018\n--------------------------\nJavaScriptEngineSwitcher has been [upgraded](https://github.com/Daniel15/JSPool/pull/29) to version 3.0.0 beta. Upgrade instructions can be found in the [How to upgrade applications to version 3.X](https://github.com/Taritsyn/JavaScriptEngineSwitcher/wiki/How-to-upgrade-applications-to-version-3.X) document. \n\nOther changes:\n - [#30](https://github.com/Daniel15/JSPool/pull/30) - Added `net471` and `netstandard2.0` targets\n - [#32](https://github.com/Daniel15/JSPool/pull/32) - Downgraded `net451` target to `net45`\n \n All changes in this release were contributed by [Andrey Taritsyn](https://github.com/Taritsyn). Thanks for your contributions!\n\n3.0 - 1st July 2017\n-------------------\n - [#7](https://github.com/Daniel15/JSPool/issues/7) - **Breaking API change**: Engines should now be returned to the pool by disposing them, rather than using `ReturnEngineToPool`:\n\nOld API:\n```csharp\nvar engine = pool.GetEngine();\nengine.CallFunction(\"doStuff\");\npool.ReturnEngineToPool(engine);\n```\n\nNew API:\n```csharp\n// with a \"using\" block\nusing (var engine = pool.GetEngine()) {\n  engine.CallFunction(\"doStuff\");\n}\n\n// without a \"using\" block\nvar engine = pool.GetEngine();\nvar message = engine.CallFunction(\"doStuff\");\nengine.Dispose();\n```\n\nThe old `ReturnEngineToPool` method still works, but it now takes an instance of `PooledJsEngine` rather than `IJsEngine`.\n\n - [#20](https://github.com/Daniel15/JSPool/issues/20) - Remove `JsEngineWithOwnThread` as it's no longer needed in `MsieJsEngine` 2.1.0 and above\n - Upgrade to latest JavaScriptEngineSwitcher\n\n2.0 - 25th September 2016\n--------------------------------\n - [#17](https://github.com/Daniel15/JSPool/issues/17) - Upgrade to JavaScriptEngineSwitcher 2.0\n - [#16](https://github.com/Daniel15/JSPool/issues/16) - Add support for .NET Core\n - [#10](https://github.com/Daniel15/JSPool/issues/10) - Add `DebounceTimeout` configuration option for specifying the number of milliseconds to wait after a file is changed before recycling the JavaScript engines.\n\n0.4.0 - 9th April 2016\n----------------------\n - Upgrade to latest JavaScriptEngineSwitcher\n\n0.3.2 - 9th April 2016\n----------------------\n - [#13](https://github.com/Daniel15/JSPool/issues/13) - Fix concurrency\n   issue\n\n0.3.1 - 15th November 2015\n--------------------------\n - [#8](https://github.com/Daniel15/JSPool/issues/8) - Do not throw if \n   `WatchPath` is used without `WatchFiles`\n - Fire `Recycled` event when pool is recycled\n\n0.3 - 12th April 2015\n---------------------\n - Added `Recycle` method to dispose all current engines and create new ones. \n   This is essentially the same as disposing the whole pool and creating a new\n   pool\n - Added the ability to recycle the pool when any watched files are modified\n\n0.2 - 21st February 2015\n------------------------\n - [#2](https://github.com/Daniel15/JSPool/issues/2) - Collect garbage when\n   engine returned to pool\n - [#3](https://github.com/Daniel15/JSPool/issues/3) - Recycle workers after a\n   certain number of usages\n - [#4](https://github.com/Daniel15/JSPool/issues/4) and\n   [#5](https://github.com/Daniel15/JSPool/issues/5) - Upgrade \n   JavaScriptEngineSwitcher to latest version to allow settings such as max heap\n   size in Web.config or App.config\n\n0.1 - 28th November 2014\n------------------------\n - Initial release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel15%2Fjspool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel15%2Fjspool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel15%2Fjspool/lists"}