parallelizer


License

License

GroupId

GroupId

com.github.takezoe
ArtifactId

ArtifactId

parallelizer_2.13
Last Version

Last Version

0.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

parallelizer
parallelizer
Project URL

Project URL

https://github.com/takezoe/parallelizer
Project Organization

Project Organization

com.github.takezoe
Source Code Management

Source Code Management

https://github.com/takezoe/parallelizer

Download parallelizer_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.takezoe/parallelizer_2.13/ -->
<dependency>
    <groupId>com.github.takezoe</groupId>
    <artifactId>parallelizer_2.13</artifactId>
    <version>0.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.takezoe/parallelizer_2.13/
implementation 'com.github.takezoe:parallelizer_2.13:0.0.6'
// https://jarcasting.com/artifacts/com.github.takezoe/parallelizer_2.13/
implementation ("com.github.takezoe:parallelizer_2.13:0.0.6")
'com.github.takezoe:parallelizer_2.13:jar:0.0.6'
<dependency org="com.github.takezoe" name="parallelizer_2.13" rev="0.0.6">
  <artifact name="parallelizer_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.takezoe', module='parallelizer_2.13', version='0.0.6')
)
libraryDependencies += "com.github.takezoe" % "parallelizer_2.13" % "0.0.6"
[com.github.takezoe/parallelizer_2.13 "0.0.6"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.1

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.0.8

Project Modules

There are no modules declared in this project.

parallelizer Build Status Maven Central License

A library offering tiny utilities for parallelization.

Installation

libraryDependencies += "com.github.takezoe" %% "parallelizer" % "0.0.6"

Usage

For example, each element of the source collection can be proceeded in parallel as the following example.

import com.github.takezoe.parallelizer.Parallel

val source: Seq[Int] = Seq(1, 2, 3)

// Run each element in parallel, but this call is blocked. Result order is preserved.
val result: Seq[Int] = Parallel.run(source){ i: Int =>
  ...
}

Parallelism can be specified as a second parameter. The default parallelism is a number of available processors.

// Run with 100 threads. Result order is preserved.
val result: Seq[Int] = Parallel.run(source, parallelism = 100){ i: Int =>
  ...
}

Parallel execution can be broken immediately by calling Parallel.break in the closure. It waits for the completion is ongoing elements, but drops all elements remaining when it called.

// Break parallel execution if terminated flag is true
val result: Seq[Int] = Parallel.run(source, parallelism = 100){ i: Int =>
  if (terminated) {
    Parallel.break
  }
  ...
}

Implicit class which offers syntax sugar to use these methods easily is also available.

import com.github.takezoe.parallelizer._

val source: Seq[Int] = Seq(1, 2, 3)

source.parallelMap(parallelism = 2){ i: Int =>
  ...
}

Versions

Version
0.0.6