Swiftpack.co - swiftwasm/OpenCombineJS as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by swiftwasm.
swiftwasm/OpenCombineJS 0.1.2
OpenCombine helpers for JavaScriptKit/WebAssembly APIs
⭐️ 24
🕓 1 week ago
.package(url: "https://github.com/swiftwasm/OpenCombineJS.git", from: "0.1.2")


OpenCombine helpers for JavaScriptKit/WebAssembly APIs. Currently it provides:


Here's an example of a timer that fetches a UUID from a remote server every second, parses it with JSValueDecoder, and then displays the result as text:

import JavaScriptKit
import OpenCombine
import OpenCombineJS

private let jsFetch = JSObject.global.fetch.function!
func fetch(_ url: String) -> JSPromise {

let document = JSObject.global.document
var p = document.createElement("p")
_ = document.body.appendChild(p)

var subscription: AnyCancellable?

let timer = JSTimer(millisecondsDelay: 1000, isRepeating: true) {
  subscription = fetch("https://httpbin.org/uuid")
    .flatMap {
    .mapError { $0 as Error }
    .map { Result<String, Error>.success($0.uuid.string!) }
    .catch { Just(.failure($0)) }
    .sink {
      let time = JSDate().toLocaleTimeString()
      switch $0 {
      case let .success(uuid):
        p.innerText = .string("At \(time) received uuid \(uuid)")
      case let .failure(error):
        p.innerText = .string("At \(time) received error \(error)")


Stars: 24
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1 week ago

This is a bugfix release that fixes infinite recursion in the use of JSValueDecoder.

Merged pull requests:

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics