Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simple async utilities for Java 5+

NotificationsYou must be signed in to change notification settings

mbouchenoire/jsync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drawing Jsync

Build Status Coverage Status

Jsync is a lightweight Java library focused on providing simple methods to deal with concurrency before the Java 8 Stream API.This library is mostly influenced by the.NET Parallel Class andasync.js.

Methods

parallel(Runnable[] runnables)

Call each givenRunnable asynchronously while beeing synchronous itself.You can pass as many runnables as you want usingvarargs, or even provide them within anArray /Collection.

Jsync.parallel(newRunnable() {publicvoidrun() {// Do some long task here...        }    },newRunnable() {publicvoidrun() {// Do some other long task there...        }    },newCustomRunnable(args)// or implement your own runnables);

forEach(T[] items, Consumer<T> consumer)

Apply each value initems to theConsumer.Each execution ofConsumer#accept() is called asynchronously while theforEach() method itself is synchronous.

String[]strings =newString[] {"hi","jsync" };Jsync.forEach(strings,newConsumer<String>() {publicvoidaccept(Stringarg) {// each execution of this function is asynchronousSystem.out.println(arg);    }});

T[] map(T[] items, Function<T, R> function)

Produces a newArray /Collection of values by mapping each value initems through theFunction.Each execution ofFunction#apply() is called asynchronously while themap() function itself is synchronous.

String[]strings =newString[] {"hi" ,"Jsync" };Integer[]lengths =Jsync.map(strings,newFunction<String,Integer>() {publicIntegerapply(Stringarg) {// each execution of this function is asynchronousreturnarg.length();    }});// lengths : [2, 5]

T[] filter(T[] items, Predicate<T> predicate)

Produces a newArray /Collection of values which pass thePredicate test.Each execution ofPredicate#test() is called asynchronously while thefilter() function itself is synchronous.

String[]strings =newString[] {"hi","jsync","this is too long" };String[]filteredStrings =Jsync.filter(strings,newPredicate<String>() {publicBooleantest(Stringarg) {// each execution of this function is asynchronousreturn (arg.length <=10);    }});// filteredStrings : [ "hi", "jsync" ]

About

Simple async utilities for Java 5+

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp