Skip to content

Instantly share code, notes, and snippets.

import org.apache.pekko.actor.{Actor, Timers, Props}
import scala.concurrent.duration.*
object RetryActor {
case object DoWork
case class RetryWork(attempt: Int)
case object WorkSucceeded
case object WorkFailed
private case object RetryTimerKey
@hanishi
hanishi / index.tsx
Last active March 7, 2024 03:36
AutocompleteServer for ChatGPT
type CacheEntry<T> = {
value: T,
timeout: ReturnType<typeof setTimeout>,
}
class ExpiringCache<T> {
private readonly cache: Record<string, CacheEntry<T>>;
private readonly expirationTime: number;
constructor(expirationTime: number = 5000) {
package actors
import actors.CpcActuator.Actor.{ FetchMeasurementKey, TimeoutKey, Work }
import akka.actor.typed.scaladsl.{ ActorContext, Behaviors, StashBuffer, TimerScheduler }
import akka.actor.typed.{ ActorRef, Behavior, SupervisorStrategy }
import akka.util.Timeout
import com.google.inject.Provides
import play.api.Configuration
import play.api.libs.concurrent.ActorModule
import usecase.SamplePublisherService
@hanishi
hanishi / Aggregator.scala
Last active November 6, 2022 13:22
Sample parent-child actors with aggregator for collecting the status of child actors.
package actors
import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.{ActorRef, Behavior}
import scala.collection.immutable
import scala.concurrent.duration.FiniteDuration
import scala.reflect.ClassTag
//see https://github.com/akka/akka/blob/v2.7.0/akka-actor-typed-tests/src/test/scala/docs/akka/typed/Aggregator.scala
@hanishi
hanishi / Child.scala
Last active November 20, 2023 09:18
Parent Child using Akka Typed
package example
import akka.Done
import akka.actor.typed.scaladsl.{
ActorContext,
Behaviors,
StashBuffer,
TimerScheduler
}
import akka.actor.typed.{ActorRef, Behavior, SupervisorStrategy}
import typings.express.mod as express
import typings.express.mod.{RequestHandler, request_=}
import typings.expressServeStaticCore.mod.*
import typings.node.bufferMod.global.Buffer
import typings.node.processMod as process
import wvlet.airframe.log
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.DurationInt
import scala.concurrent.{ExecutionContext, Future}
package example
import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.AskPattern.{Askable, schedulerFromActorSystem}
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import example.asyncHandler.{Req, Res}
import org.scalablytyped.runtime.StringDictionary
import typings.express.mod as express
import typings.node.bufferMod.global.Buffer
package example
import akka.Done
import akka.actor.typed.scaladsl.{ActorContext, Behaviors, StashBuffer, TimerScheduler}
import akka.actor.typed.{ActorRef, Behavior, SupervisorStrategy}
import akka.pattern.StatusReply
import org.scalablytyped.runtime.StringDictionary
import typings.cheerio.cheerioMod.Cheerio
import typings.cheerio.mod.Node
import typings.devtoolsProtocol.mod.Protocol.Network.ResourceType
package example
import akka.actor.typed.scaladsl.{ActorContext, Behaviors, StashBuffer}
import akka.actor.typed.{ActorRef, Behavior, SupervisorStrategy}
import akka.pattern.StatusReply
import akka.util.Timeout
import typings.node.bufferMod.global.Buffer
import typings.puppeteer.mod.Browser
import java.util.UUID.randomUUID
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1")
addSbtPlugin("org.scalablytyped.converter" % "sbt-converter" % "1.0.0-beta36")