Class: Flor::Pro::Trap

Inherits:
Flor::Procedure show all
Defined in:
lib/flor/punit/trap.rb

Overview

Would it be worth the pain implementing bind:?

Constant Summary

Constants inherited from Flor::Procedure

Flor::Procedure::RVARS, Flor::Procedure::TRUE_ATTS

Instance Attribute Summary

Attributes inherited from Node

#message

Instance Method Summary collapse

Methods inherited from Flor::Procedure

[], core?, #debug_msg, #debug_tree, #end, #flank, #heap, inherited, make, names, #prepare_on_receive_last, #trigger_on_error

Methods inherited from Node

#child_id, #cnodes, #cnodes_any?, #cnodes_empty?, #deref, #descendant_of?, #domain, #exid, #fei, #from, #h, #initialize, #lookup_tree, #lookup_value, #message_or_node_payload, #nid, #node_closed?, #node_ended?, #node_open?, #node_payload, #node_payload_ret, #node_status, #node_status_flavour, #on_error_parent, #parent, #payload, #payload_ret, #point, #reheap, #to_procedure_node, #tree

Constructor Details

This class inherits a constructor from Flor::Node

Instance Method Details

#pre_executeObject



225
226
227
228
229
230
231
232
# File 'lib/flor/punit/trap.rb', line 225

def pre_execute

  @node['vars'] = {}
  @node['atts'] = []
  @node['fun'] = nil

  #unatt_unkeyed_children
end

#receiveObject



291
292
293
294
295
296
# File 'lib/flor/punit/trap.rb', line 291

def receive

  return [] if @node['trapped']

  super
end

#receive_lastObject



286
287
288
289
# File 'lib/flor/punit/trap.rb', line 286

def receive_last

  receive_non_att
end

#receive_non_attObject



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/flor/punit/trap.rb', line 234

def receive_non_att

  fun = @fcid > 0 ? payload['ret'] : nil

  points = att_a('point', 'points', nil)
  tags = att_a('tag', 'tags', nil)
  heats = att_a('heat', 'heats', nil)
  heaps = att_a('heap', 'heaps', nil)
  names = att_a('name', 'names', nil)
  pl = att('payload', 'pl') || 'trap'

  points = att_a(nil, nil) unless points || tags
  points = [ 'entered' ] if tags && ! points

  att_a('sig', 'signal', 'signals', [])
    .each { |sig| (points ||= []) << 'signal'; (names ||= []) << sig }

  points = points.uniq if points
  names = names.uniq if names

  bnid = att('bnid', 'bind') || parent || '0'

  msg =
    if fun
      apply(fun, [], tree[2], anid: false).first
    else
      wrap_reply.first
    end

  tra = {}
  tra['nid'] = nid
  tra['bnid'] = bnid
  tra['points'] = points
  tra['tags'] = tags
  tra['heaps'] = heaps
  tra['heats'] = heats
  tra['names'] = names
  tra['message'] = msg
  tra['pl'] = pl

  count = att('count')
  count = 1 if fun == nil # blocking mode implies count: 1
  tra['count'] = count if count

  tra['range'] = att('range', 'scope') || 'subnid'

  @node['trapped'] = true

  wrap('point' => 'trap', 'nid' => nid, 'trap' => tra) +
  (fun ? flank : [])
end

#wrap_cancel_children(h = {}) ⇒ Object

“trap” keeps track of its children, but does not cascade ‘cancel’ to them, unless the cancel flavour is ‘kill’.



301
302
303
304
# File 'lib/flor/punit/trap.rb', line 301

def wrap_cancel_children(h={})

  h['flavour'] == 'kill' ? super : []
end