Releasing thread and URL reference when the workerized function is not needed
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript
- Lĩnh vực
- web-dev
Hướng nghiên cứu
Bắt đầu với mã nguồn xung quanh việc tạo workerURL và lệnh gọi new Worker, sau đó so sánh với ví dụ trong README sử dụng greenlet. Xác định xem hàm được trả về có nên cung cấp cơ chế giải phóng hay không, cũng như cần thực hiện việc dọn dẹp hoặc hành vi nào sau khi giải phóng. Được xem là hoàn tất khi quyết định về vòng đời tài nguyên được triển khai nhất quán với API được đề xuất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Great library, very useful stuff and absolutely love the size. :)
I've only recently started learning about Web Workers and took a look at the source code. So apologies in advance if I am wrong ;). 2 things caught my eyes:
const workerURL = URL.createObjectURL(new Blob([script]));
// Create an "inline" worker (1:1 at definition time)
const worker = new Worker(workerURL);
So if we do something like the following snippet (taken from the README), it seems that each new function instantiated via greenlet(...) will reserve a new thread and a new URL reference.
import greenlet from 'greenlet'
let getName = greenlet( async username => {
let url = `https://api.github.com/users/${username}`
let res = await fetch(url)
let profile = await res.json()
return profile.name
})
console.log(await getName('developit'))
So, if there is a case wherein I don't need to use getName after a certain point in my code, those resources are still trapped. They may be very less in size to be of a practical concern, but I am not sure about it and would love if anyone can comment on that.
However, if the output function getName comes with a dispose method which releases those references, it could be useful. WDYT? Something like:
getName.dispose() // Release references
Internally, it could call:
window.URL.revokeObjectURL(workerURL);
worker.terminate();
Post dispose, getName can itself become undefined so it's not callable. Or can throw a more informative error: The function is disposed/discarded due to .dispose() call..
Is there a downside to this approach if the contributors already considered any similar approach?
- Ngôn ngữ chính
- JavaScript
- Star
- 4.7k
- Fork
- 97
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của developit/greenlet
-
support module workers? Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
_ref is not defined Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Tất cả issue của developit/greenlet
Issue tương tự
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Improve Title Support Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·