Skip to content

A publisher subclass for running async functions.

Notifications You must be signed in to change notification settings

pmick/TaskPublisher

Repository files navigation

TaskPublisher

A publisher that executes an async function.

searchTextPublisher
    .removeDuplicates()
    .debounce(for: .milliseconds(200), scheduler: RunLoop.main)
    .map { query in
        TaskPublisher {
            return try await httpClient.searchUsers(query)
        }
        .handleEvents(receiveCompletion: { completion in
            if case .failure = completion {
                // Show some error UI
            }
        })
        // Prevent outer publisher from failing so that future searches work
        .replaceError(with: [])
    }
    .switchToLatest()
    .sink { [weak self] users in
        self?.applySnapshot(users)
    }
    .store(in: &bag)

About

A publisher subclass for running async functions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages