def delegate(workitem, new_owner)

      hwi = fetch(workitem)

      fail ArgumentError.new(
        "workitem not found"
      ) if hwi == nil

      fail ArgumentError.new(
        "cannot delegate, workitem doesn't belong to anyone"
      ) if hwi['owner'] == nil

      fail ArgumentError.new(
        "cannot delegate, " +
        "workitem owned by '#{hwi['owner']}', not '#{workitem.owner}'"
      ) if hwi['owner'] != workitem.owner

      hwi['owner'] = new_owner

      r = @context.storage.put(hwi, :update_rev => true)

      fail ArgumentError.new("workitem is gone") if r == true
      fail ArgumentError.new("workitem got modified meanwhile") if r != nil

      Workitem.new(hwi)
    end
def delegate(workitem, new_owner)

      hwi = fetch(workitem)

      fail ArgumentError.new(
        "workitem not found"
      ) if hwi == nil

      fail ArgumentError.new(
        "cannot delegate, workitem doesn't belong to anyone"
      ) if hwi['owner'] == nil

      fail ArgumentError.new(
        "cannot delegate, " +
        "workitem owned by '#{hwi['owner']}', not '#{workitem.owner}'"
      ) if hwi['owner'] != workitem.owner

      hwi['owner'] = new_owner

      r = @context.storage.put(hwi, :update_rev => true)

      fail ArgumentError.new("workitem is gone") if r == true
      fail ArgumentError.new("workitem got modified meanwhile") if r != nil

      Workitem.new(hwi)
    end
Delegates a currently owned workitem to a new owner.

 Fails if the workitem can't be found, belongs to noone, or if the
 workitem passed as argument is out of date (got modified in the mean
 time).

 It's OK to delegate to nil, thus freeing the workitem.

 See #reserve for an an explanation of the reserve/delegate/proceed flow.