Sha256: 8f08259e7c6da80a8bd3c5333ac0159fff87753841e8a028e4bb55834ef9fc7a

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

# = Thread Related Extensions
#
# Thread extensions, in particular for Enumerable --send
# a message to each member via a thread and collect the results.
#
# == Authors
#
# * Sean O'Halpin
#
# == Todo
#
# * Better names for these methods ?
#
# == Copying
#
# Copyright (c) 2006 Sean O'Halpin
#
# Ruby License
#
# This module is free software. You may use, modify, and/or redistribute this
# software under the same terms as Ruby.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.

require 'thread'
require 'facets/enumerable/map_send'

module Enumerable

  # Like Enumerable#map but each iteration is processed via
  # a separate thread.
  #
  # CREDIT Sean O'Halpin

  def threaded_map #:yield:
    map{ |e| Thread.new(e){ |t| yield(t) } }.map{ |t| t.value }
  end

  # Like Enumerable#map_send but each iteration is processed via
  # a separate thread.
  #
  # CREDIT Sean O'Halpin

  def threaded_map_send(meth, *args, &block)
    map{ |e| Thread.new(e){ |t| t.send(meth, *args, &block) } }.map{ |t| t.value }
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/more/facets/thread.rb
facets-2.8.3 lib/more/facets/thread.rb
facets-2.8.2 lib/more/facets/thread.rb
facets-2.8.1 lib/more/facets/thread.rb
facets-2.8.0 lib/more/facets/thread.rb
facets-2.7.0 lib/more/facets/thread.rb
facets-2.6.0 lib/more/facets/thread.rb
facets-2.5.1 lib/more/facets/thread.rb
facets-2.5.0 lib/more/facets/thread.rb
facets-2.5.2 lib/more/facets/thread.rb