Skip to content

Commit

Permalink
Improve thread cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
howmanysmall committed Jul 1, 2023
1 parent 127ac93 commit 8d8819b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.15.3] - 2023-07-01

### Changed

- Changed how threads are cleaned up internally.

## [1.15.2] - 2023-04-11

### Changed
Expand Down
2 changes: 1 addition & 1 deletion docs/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ HttpService.HttpEnabled = HttpEnabled`}

```toml
[dependencies]
Janitor = "howmanysmall/janitor@^1.15.2"
Janitor = "howmanysmall/janitor@^1.15.3"
```

## Next
Expand Down
39 changes: 36 additions & 3 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,18 @@ function Janitor:Remove(Index: any)
if type(Object) == "function" then
Object()
else
pcall(task.cancel, Object)
local Cancelled
if coroutine.running() ~= Object then
Cancelled = pcall(function()
task.cancel(Object)
end)
end

if not Cancelled then
task.defer(function()
task.cancel(Object)
end)
end
end
else
local ObjectMethod = Object[MethodName]
Expand Down Expand Up @@ -393,7 +404,18 @@ function Janitor:RemoveList(...: any)
if type(Object) == "function" then
Object()
else
pcall(task.cancel, Object)
local Cancelled
if coroutine.running() ~= Object then
Cancelled = pcall(function()
task.cancel(Object)
end)
end

if not Cancelled then
task.defer(function()
task.cancel(Object)
end)
end
end
else
local ObjectMethod = Object[MethodName]
Expand Down Expand Up @@ -577,7 +599,18 @@ function Janitor:Cleanup()
if type(Object) == "function" then
Object()
else
pcall(task.cancel, Object)
local Cancelled
if coroutine.running() ~= Object then
Cancelled = pcall(function()
task.cancel(Object)
end)
end

if not Cancelled then
task.defer(function()
task.cancel(Object)
end)
end
end
else
local ObjectMethod = Object[MethodName]
Expand Down
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "A garbage collector object implementation for Roblox, featuring s
license = "MIT"
realm = "shared"
registry = "https://github.com/UpliftGames/wally-index"
version = "1.15.2"
version = "1.15.3"
exclude = [
"docs", ".moonwave", "test",
"Janitor.rbxm", "Janitor.rbxmx", "BuildJanitor.lua",
Expand Down

0 comments on commit 8d8819b

Please sign in to comment.