![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
decorator-synchronized
Advanced tools
function decorator which ensures that calls do not run simultaneously
Function decorator which ensures that calls do not run simultaneously.
Requires WeakMap, it your system does not have it, use a polyfill.
Installation of the npm package:
> npm install --save decorator-synchronized
import { synchronized } from "decorator-synchronized";
let i = 0;
const fn = synchronized(() => {
console.log(i);
return Promise.resolve().then(() => {
i++;
});
});
Promise.all([fn(), fn()]);
// => Prints 0 then 1
// Create a dedicated synchronizer which will be shared amongst
// multiple functions.
//
// Useful when functions work on the same resource.
const counterSynchronized = synchronized();
const increment = counterSynchronized(async () => {
const i = 1 + (await db.getCounter());
await db.setCounter(i);
return i;
});
const decrement = counterSynchronized(async () => {
const i = -1 + (await db.getCounter());
await db.setCounter(i);
return i;
});
increment().then(console.log); // prints 1
decrement().then(console.log); // prints 0
withKey
import { synchronized } from "decorator-synchronized";
const updateUser = synchronized.withKey()(async (userId, props) => {
const user = await db.getUser(userId);
await db.setUser(userId, { ...user, ...props });
});
// will correctly update the user without race conditions
updaterUser("wq1567e", { foo: 3.14 });
updaterUser("wq1567e", { bar: 42 });
// different users are still updated in parallel
updateUser("ct356tv", { baz: 2.72 });
The key is deduced from the first argument, if you need something else, just provide a key function:
const fn = synchronized.withKey((_, secondArg) => secondArg)(
(firstArg, secondArg) => {
// TODO
}
);
# Install dependencies
> yarn
# Run the tests
> yarn test
# Continuously compile
> yarn dev
# Continuously run the tests
> yarn dev-test
# Build for production
> yarn build
Contributions are very welcomed, either on the documentation or on the code.
You may:
ISC © Pierre Donias
FAQs
function decorator which ensures that calls do not run simultaneously
The npm package decorator-synchronized receives a total of 370 weekly downloads. As such, decorator-synchronized popularity was classified as not popular.
We found that decorator-synchronized demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.