Cleanup (#14) Update Update Update Update
Cleanup (#14)
Update
Bulk is a library for buffering the objects. Pipeline(Sink) receives the object and emits the object bulked.
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.
We call the pipeline that receives the object as Sink.
Sink
Sink receives the objects and emits the bulked object to multiple targets.
To create a bulk, we can choose several types of the buffer. Currently, Bulk provides 2 types below.
In this tutorial, we select MemoryBuffer.
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).
sink
The Logger as a library on top of Bulk.
BulkLogger provies Logger object that wraps Sink inside.
Logger
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")
Bulk Framework is released under the MIT License.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
Bulk / BulkLogger
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.
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.To create a bulk, we can choose several types of the buffer.
Currently, Bulk provides 2 types below.
In this tutorial, we select MemoryBuffer.
Target receives the bulked object from Sink.
Bulk does not privides default implemented Target.
For now, you need to create it.
And finally, create BulkSink object.
Send the objects
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 wrapsSink
inside.Logger object send the log data to 2 targets (LogConsoleTarget and OSLogTarget)
LICENSE
Bulk Framework is released under the MIT License.