square / square/workflow-swift

Consider something like LifecycleWorker

Open
#71 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Swift
Stars
373
Forks
46
Avg merge
6h 38m
Merged PRs (30d)
3

Description

Kotlin has LifecycleWorker that makes it easy to perform side-effects when the worker is started or stopped.

At the moment, this is essentially equivalent to doing the following in Swift:

func render(state: State, context: RenderContext<SomeWorkflow>) -> Rendering {
    let onStart: () -> Void = …
    let onEnd: () -> Void = …

    context.runSideEffect(key: "lifecycle") { lifetime in
        onStart()
        lifetime.onEnded(onEnd)
    }

    …
}

We might consider making some convenience for this in Swift land. I’d hesitate tying it to Worker specifically since that lives in WorkflowReactiveSwift and this could be built more generally.

Open to suggestions on API shape

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked Kotlin LifecycleWorker.kt and the Swift render example using RenderContext.runSideEffect. Review how lifecycle effects are currently represented in Swift, then clarify the proposed API shape and its scope beyond Worker. Done means an agreed, documented convenience API with tests covering worker start and stop behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, swift
Domain
mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.