{"id":25082197,"url":"https://github.com/niksativa/defferedtaskkit","last_synced_at":"2025-06-14T08:06:51.798Z","repository":{"id":173779856,"uuid":"651211106","full_name":"NikSativa/DefferedTaskKit","owner":"NikSativa","description":"DefferedTaskKit is a simple library for wrapping closures that can be executed at a later time","archived":false,"fork":false,"pushed_at":"2025-01-30T10:30:29.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T15:17:29.328Z","etag":null,"topics":["async","closure","deffered","ios","pending","polling","swift","task"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NikSativa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-08T18:49:20.000Z","updated_at":"2025-01-30T10:30:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"c1c0142d-1daf-49f2-8459-fe701634fba3","html_url":"https://github.com/NikSativa/DefferedTaskKit","commit_stats":null,"previous_names":["niksativa/ndefferedtask"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FDefferedTaskKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FDefferedTaskKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FDefferedTaskKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FDefferedTaskKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NikSativa","download_url":"https://codeload.github.com/NikSativa/DefferedTaskKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246621268,"owners_count":20806923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","closure","deffered","ios","pending","polling","swift","task"],"created_at":"2025-02-07T05:29:05.827Z","updated_at":"2025-04-01T10:23:53.026Z","avatar_url":"https://github.com/NikSativa.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DefferedTaskKit\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FNikSativa%2FDefferedTaskKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/NikSativa/DefferedTaskKit)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FNikSativa%2FDefferedTaskKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/NikSativa/DefferedTaskKit)\n\nDefferedTaskKit is a simple library for wrapping closures that can be executed at a later time.\n\n### DefferedTask\nDefferedTask works with Value, but DefferedResult is working with Result type.\n\n\u003e [!IMPORTANT]\n\u003e 1. Task will be executed only on subscription by 'onComplete' method'. If you don't subscribe to the task, it will never be executed.\n\u003e 2. By default, the task is 'selfRetaint' and you don't need save reference in variables for task. Use 'weakify()' method to prevent retain cycle.\n\u003e 3. You can handle 'deinit' of task if you need.\n\n### DefferedTask\n\n```swift\nDefferedTask\u003cInt\u003e { completion in\n    print(\"start task\")\n    DispatchQueue.main.asyncAfter(deadline: .now() + 1) {\n        completion(10)\n        print(\"end task\")\n    }\n} onDeinit: {\n    print(\"onDeinit\")\n}\n.beforeComplete { result in\n    print(\"beforeComplete: \\(result)\") // print 10\n}\n.afterComplete { result in\n    print(\"afterComplete: \\(result)\") // print 10\n}\n.set(userInfo: \"subject\")\n.strongify()\n.map { value in\n    return value * 2\n}\n.beforeComplete { result in\n    print(\"beforeComplete: \\(result)\") // print 20\n}\n.afterComplete { result in\n    print(\"afterComplete: \\(result)\") // print 20\n}\n.onComplete { result in\n    print(\"onComplete: \\(result)\") // print 20\n}\n```\n\nconsole output:\n```\nstart task\nbeforeComplete: 10\nbeforeComplete: 20\nonComplete: 20\nafterComplete: 20\nafterComplete: 10\nonDeinit\nend task\n```\n\n### PendingTask\nSpecial task that is caching tasks while executing single main task.\n\n```swift\nlet pending: PendingTask\u003cInt\u003e = .init()\n\nfor i in 0..\u003c10 {\n    pending.current { completion in\n        print(\"start main task\")\n        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {\n            completion(10)\n            print(\"end main task\")\n        }\n    }.onComplete { _ in\n        print(\"onComplete: \\(i)\")\n    }\n}\n```\n\nconsole output:\n```\nstart main task\nonComplete: 0\nonComplete: 1\nonComplete: 2\nonComplete: 3\nonComplete: 4\nonComplete: 5\nonComplete: 6\nonComplete: 7\nonComplete: 8\nonComplete: 9\nend main task\n```\n\n### PollingTask\nSpecial task that is polling main task with idleTimeInterval and retryCount.\n\n```swift\nvar idx = 0\nPollingTask\u003cInt\u003e(idleTimeInterval: 1,\n                 retryCount: 5,\n                 generator: {\n    return .init { completion in\n        print(\"start main task\")\n        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {\n            completion(idx)\n            idx += 1\n            print(\"end main task\")\n        }\n    }\n},\n                 shouldRepeat: { idx in\n    print(\"shouldRepeat \\(idx)\")\n    return idx \u003c 4\n},\n                 response: { idx in\n    print(\"response: \\(idx)\")\n})\n.start()\n.onComplete { result in\n    print(\"completed \\(result)\")\n} \n```\n\nconsole output:\n```\nstart main task\nresponse: 0\nshouldRepeat 0\nend main task\nstart main task\nresponse: 1\nshouldRepeat 1\nend main task\nstart main task\nresponse: 2\nshouldRepeat 2\nend main task\nstart main task\nresponse: 3\nshouldRepeat 3\nend main task\nstart main task\nresponse: 4\nshouldRepeat 4\ncompleted 4\nend main task\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksativa%2Fdefferedtaskkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniksativa%2Fdefferedtaskkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksativa%2Fdefferedtaskkit/lists"}