Skip to content

Commit

Permalink
0.6.2 - Don't require a running asyncio loop to instantiate the REST …
Browse files Browse the repository at this point in the history
…API class
  • Loading branch information
jacobsvante committed Apr 25, 2021
1 parent d175c38 commit f608db9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions netsuite/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Sequence

from . import json
from .util import cached_property

try:
import httpx
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <m@jacobian.se>"]
license = "MIT"
Expand Down

0 comments on commit f608db9

Please sign in to comment.