From 8d8819b0a4d6f391a3d557909574f55d635ab3b4 Mon Sep 17 00:00:00 2001 From: howmanysmall Date: Sat, 1 Jul 2023 12:12:21 -0600 Subject: [PATCH] Improve thread cleaning --- changelog.md | 6 ++++++ docs/Installation.md | 2 +- src/init.lua | 39 ++++++++++++++++++++++++++++++++++++--- wally.toml | 2 +- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index cd8d39b..288f272 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/docs/Installation.md b/docs/Installation.md index 4838332..adf6c09 100644 --- a/docs/Installation.md +++ b/docs/Installation.md @@ -99,7 +99,7 @@ HttpService.HttpEnabled = HttpEnabled`} ```toml [dependencies] -Janitor = "howmanysmall/janitor@^1.15.2" +Janitor = "howmanysmall/janitor@^1.15.3" ``` ## Next diff --git a/src/init.lua b/src/init.lua index e8c7f0a..a84643c 100644 --- a/src/init.lua +++ b/src/init.lua @@ -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] @@ -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] @@ -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] diff --git a/wally.toml b/wally.toml index 42ab8e0..dc69244 100644 --- a/wally.toml +++ b/wally.toml @@ -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",