Skip to content

Instantly share code, notes, and snippets.

@goloveychuk
Created March 5, 2016 18:31
Show Gist options
  • Save goloveychuk/70c7e9ac6c22effade3c to your computer and use it in GitHub Desktop.
Save goloveychuk/70c7e9ac6c22effade3c to your computer and use it in GitHub Desktop.
// //
// // main.swift
// // broq_swift
// //
// // Created by badim on 1/19/16.
// // Copyright © 2016 badim. All rights reserved.
// //
import SwiftZMQ
import Venice
let context = try! Context()
let inbound = try! context.socket(.Sub)
try! inbound.connect("tcp://dv:8082")
try! inbound.setSubscribe("")
let fd = try! inbound.getFileDescriptor()
let channel1 = Channel<[Int8]>()
co {
while true {
let polled = Venice.poll(fd, events: .Read)
guard polled == .Read else {
continue
}
repeat {
guard let msg = try! inbound.receive() else {
continue
}
channel1 <- msg
} while (try! inbound.getEvents() == .In)
}
}
after(1 * second) {
print("yoo")
}
forSelect { when, done in
when.receiveFrom(channel1) { message1 in
print("received \(message1)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment