Bulk 0.7.0

Bulk 0.7.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Mar 2020
SPMSupports SPM

Maintained by muukii, muukii.



Bulk 0.7.0

Bulk / BulkLogger

Version platforms

Bulk is a library for buffering the objects. Pipeline(Sink) receives the object and emits the object bulked.

What is for?

To pack a lot of elements would be helpful in several cases. For example, sending the analytics events for your products with in house API.

  • collect the many events
  • pack it into one
  • send these events as a set of events.

Bulk module

Make a sink

We call the pipeline that receives the object as Sink.

Sink receives the objects and emits the bulked object to multiple targets.

  1. Select the buffer.

To create a bulk, we can choose several types of the buffer.
Currently, Bulk provides 2 types below.

  • MemoryBuffer
  • FileBuffer

In this tutorial, we select MemoryBuffer.

  1. Create the target

Target receives the bulked object from Sink.

Bulk does not privides default implemented Target.
For now, you need to create it.

public protocol TargetType {

  associatedtype Element

  func write(items: [Element])
}
struct MyTarget<Element>: TargetType {

  func write(items: [Element]) {
    print(items)
  }
}

And finally, create BulkSink object.

let sink = BulkSink<String>(
  buffer: MemoryBuffer.init(size: 10).asAny(),
  targets: [
    MyTarget<String>().asAny()
  ]
)

Send the objects

sink.send("A")
sink.send("B")
sink.send("C")

sink sends the bulked object when Buffer receives the objects up to the specified size (10 elements in the example).

BulkLogger module

The Logger as a library on top of Bulk.

BulkLogger provies Logger object that wraps Sink inside.

let logger = Logger(context: "", sinks: [
  BulkSink<LogData>(
    buffer: MemoryBuffer.init(size: 10).asAny(),
    targets: [

      TargetUmbrella.init(
        transform: LogBasicFormatter().format,
        targets: [
          LogConsoleTarget.init().asAny()
        ]
      ).asAny(),

      OSLogTarget(subsystem: "BulkDemo", category: "Demo").asAny()
    ]
  )
    .asAny()
])

Logger object send the log data to 2 targets (LogConsoleTarget and OSLogTarget)

logger.verbose("Hello")

LICENSE

Bulk Framework is released under the MIT License.