diff --git a/CHANGELOG.md b/CHANGELOG.md index dd9e48d..646fae6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Nothing +## [0.6.2](https://github.com/jmagnusson/netsuite/compare/v0.6.1...v0.6.2) - 2021-04-25 + +### Fixed +- `NetSuiteRestApi` no longer requires a running asyncio loop to be instantiated + ## [0.6.1](https://github.com/jmagnusson/netsuite/compare/v0.6.0...v0.6.1) - 2021-04-25 ### Fixed diff --git a/netsuite/rest_api.py b/netsuite/rest_api.py index 48e404c..b3ac33c 100644 --- a/netsuite/rest_api.py +++ b/netsuite/rest_api.py @@ -3,6 +3,7 @@ from typing import Sequence from . import json +from .util import cached_property try: import httpx @@ -62,7 +63,13 @@ def __init__( self._token_secret = token_secret self._hostname = self._make_hostname() self._default_timeout = default_timeout - self._request_semaphore = asyncio.Semaphore(concurrent_requests) + self._concurrent_requests = concurrent_requests + + @cached_property + def request_semaphore(self) -> asyncio.Semaphore: + # NOTE: Shouldn't be put in __init__ as we might not have a running + # event loop at that time. + return asyncio.Semaphore(self._concurrent_requests) @classmethod def has_required_dependencies(cls) -> bool: @@ -157,7 +164,7 @@ async def _raw_request( f"Making {method.upper()} request to {url}. Keyword arguments: {kw}" ) - async with self._request_semaphore: + async with self.request_semaphore: async with httpx.AsyncClient() as c: resp = await c.request( method=method, diff --git a/pyproject.toml b/pyproject.toml index ec12ea1..8382ae2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "netsuite" -version = "0.6.1" +version = "0.6.2" description = "Wrapper around Netsuite SuiteTalk SOAP/REST Web Services and Restlets." authors = ["Jacob Magnusson "] license = "MIT"