Skip to content

Instantly share code, notes, and snippets.

View durre's full-sized avatar

Andreas Du Rietz durre

  • Stockholm / Sweden
View GitHub Profile
@durre
durre / app.ts
Last active November 17, 2023 07:10
A bit more extensive example to go with the article, https://durre.se/you-might-not-need-javascript-classes. Here we wire "everything" up and show how it can be tested.
import { createOrderDao } from './orderDao'
import { createProductDao } from './productDao'
import { createPaymentService } from './paymentService'
import { createOrderService } from './orderService'
const orderDao = createOrderDao()
const productDao = createProductDao()
const paymentService = createPaymentService()
const orderService = createOrderService({ orderDao, productDao, paymentService })
object FutureUtils {
def sequenceOr[T](result: Or[Future[T], ErrorMessage]): Future[Or[T, ErrorMessage]] = {
result match {
case Good(futureValue) => futureValue.map(Good(_))
case Bad(msg) => Future.successful(Bad(msg))
}
}
}
import akka.actor.ActorLogging
import akka.stream.actor.ActorPublisher
import akka.util.ByteString
import com.rabbitmq.client._
class RabbitConsumerActor(connection: Connection, queue: Queue) extends ActorPublisher[RabbitMessage] with ActorLogging {
val channel = connection.createChannel()
val consumer = new DefaultConsumer(channel) {
override def handleDelivery(consumerTag: String, envelope: Envelope, properties: AMQP.BasicProperties, body: Array[Byte]) =