puter.workers.delete()
Deletes an existing worker and stops its execution.
puter.workers.delete(workerName)
workerName
(String)(Required)
The name of the worker to delete.
A Promise
that resolves to true
if successful, or throws an Error
if the operation fails.
Basic Worker Deletion
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
// (1) Create a random worker
let workerName = puter.randName();
const worker = await puter.workers.create(workerName, 'example-worker.js')
puter.print(`Worker deployed at: ${worker.url} (This is an empty worker with no code)<br>`);
// (2) Delete the worker using delete()
const worker2 = await puter.workers.delete(workerName);
puter.print('Worker deleted<br>');
// (3) Try to retrieve the worker (should fail)
puter.print('Trying to retrieve worker... (should fail)<br>');
try {
await puter.workers.get(workerName);
} catch (e) {
puter.print('Worker could not be retrieved<br>');
}
})();
</script>
</body>
</html>